dotnet / dotnet/macios

Xamarin iOS - Objective - C Binding: No implicit reference conversion between Objecttype and NSObject

Open
#10,783 0 comments 0 reactions 0 assignees View on GitHub
generator iOS
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 12h
Merged PRs (30d)
123

Description

I have a Problem with a Xamarin.iOS Objective-C Binding. I'm using Objective Sharpie 3.5.41 to generate the ApiDefinitions and StructsAndEnums. I'm generating an Intent Protocol Definition with Custom Intent Type.

The Problem is that the Object `IntentAppliance` is typed to `INObject` cannot implicitly used as a type for an `INObjectCollection`. The method
```
[Abstract]
[Export ("provideApplianceOptionsCollectionForApplianceSelection:withCompletion:")]
void ProvideApplianceOptionsCollectionForApplianceSelection (ApplianceSelectionIntent intent, Action, NSError> completion);
```
creates the Error
```
ApiDefinitions.cs(150,150): Error CS0311: The type 'IntentBinding.IntentAppliance' cannot be used as type parameter 'ObjectType' in the generic type or method 'INObjectCollection'. There is no implicit reference conversion from 'IntentBinding.IntentAppliance' to 'Foundation.NSObject'.
```

The Definition of the class `IntentApplaince`:
```
[Watch (5,0), NoTV, Mac (10,16), iOS (12,0)]
[BaseType (typeof(INObject))]
interface IntentAppliance
{
// @property (readwrite, copy, nonatomic) NSString * _Nullable id __attribute__((availability(ios, introduced=13.0))) __attribute__((availability(macos, introduced=10.16))) __attribute__((availability(watchos, introduced=6.0)));
//[Watch (6, 0), Mac (10, 16), iOS (13, 0)]
[NullAllowed, Export ("id")]
string Id { get; set; }
}
```

### Steps to Reproduce

1. Create Intent Definition File with Xcode which includes a self designed Type
2. Create a static Objective-C Library from the generated Classes from the Intent Definition File
3. Add Native Reference to the static Library
4. Create ApiDefiniton and StructsAndEnums with Objective Sharpie 3.5.41 with the following Command `sharpie bind --output=. --namespace=IntentBinding -sdk iphoneos$(shell xcrun --show-sdk-platform-version --sdk iphoneos) --scope ../iOS.Native ../iOS.Native/IntentDefintionStaticLib/*.h`

### Expected Behavior
A Generated and compilable `ApiDefinistion.cs` and `StructsAndEnum.cs`
### Actual Behavior

### Environment

```
=== Visual Studio Community 2019 for Mac ===

Version 8.8.10 (build 2)
Installation UUID: 15e61cf8-1958-4c13-8382-8b037596ad0e
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 612000122

=== Mono Framework MDK ===

Runtime:
Mono 6.12.0.122 (2020-02/c621c35ffa0) (64-bit)
Package version: 612000122

=== Roslyn (Language Service) ===

3.8.0-5.20519.18+4c195c3ac1974edcefa76774d7a59a2350ec55fa

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.103/Sdks
SDK Versions:
5.0.103
5.0.102
5.0.101
5.0.100
3.1.406
3.1.405
3.1.404
3.1.403
3.1.402
3.1.401
3.1.300
3.1.202
3.1.200
3.1.102
3.1.101
3.1.100
3.0.101
3.0.100
2.2.100
2.1.701
2.1.700
2.1.505
2.1.302
2.1.301
2.1.4
2.0.0
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
5.0.3
5.0.2
5.0.1
5.0.0
3.1.12
3.1.11
3.1.10
3.1.9
3.1.8
3.1.7
3.1.4
3.1.2
3.1.1
3.1.0
3.0.1
3.0.0
2.2.0
2.1.23
2.1.22
2.1.21
2.1.18
2.1.17
2.1.16
2.1.15
2.1.14
2.1.13
2.1.12
2.1.11
2.1.9
2.1.2
2.1.1
2.0.5
2.0.0

=== .NET Core 3.1 SDK ===

SDK: 3.1.406

=== Xamarin.Profiler ===

Version: 1.6.12.26
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 12.4 (17801)
Build 12D4e

=== Xamarin.Mac ===

Version: 7.4.0.10 (Visual Studio Community)
Hash: a4c70e7d0
Branch: xcode12.4
Build date: 2021-02-17 17:40:51-0500

=== Xamarin.iOS ===

Version: 14.10.0.4 (Visual Studio Community)
Hash: 5a05865f6
Branch: xcode12.4
Build date: 2021-01-28 02:30:23-0500

=== Xamarin Designer ===

Version: 16.8.0.510
Hash: 44e3f3ce9
Branch: remotes/origin/d16-8
Build date: 2020-12-10 00:06:14 UTC

=== Xamarin.Android ===

Version: 11.1.0.26 (Visual Studio Community)
Commit: xamarin-android/d16-8/a36ce73
Android SDK: /Users/sprenger_m/Library/Android/sdk
Supported Android versions:
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.1
SDK Build Tools Version: 30.0.0 rc1

Build Information:
Mono: 5e9cb6d
Java.Interop: xamarin/java.interop/d16-8@79d9533
ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
SQLite: xamarin/sqlite/3.32.1@1a3276b
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/sprenger_m/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.8.0.32
Hash: 01a7774
Branch: remotes/origin/d16-8
Build date: 2021-01-14 00:34:58 UTC

=== Android Device Manager ===

Version: 16.8.0.46
Hash: 0a81419
Branch: remotes/origin/d16-8
Build date: 2021-01-14 00:35:22 UTC

=== Build Information ===

Release ID: 808100002
Git revision: f81ffa2444a28c09f173849935ec9ee0195a5b17
Build date: 2021-02-18 12:02:12-05
Build branch: release-8.8
Xamarin extensions: f81ffa2444a28c09f173849935ec9ee0195a5b17

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.3.0 Darwin Kernel Version 20.3.0
Thu Jan 21 00:07:06 PST 2021
root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

MSBuild Editor 2.4.0

```

### Build Logs

### Example Project (If Possible)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.