-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of INSCopying in binding library causes CS8767 nullability warning #17130
Comments
Because the Even better, an extension method such as follows, which also keeps the result strongly typed. public static T Copy<T>(this T obj) where T : NSObject, INSCopying => (T)obj.Copy(NSZone.Default); |
Oh wait, nevermind about my last suggestion. It seems that So I guess there's not much point in even applying |
This is the implementation of NSObject.Copy: [Export ("copy")]
[return: ReleaseAttribute ()]
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
public virtual NSObject Copy ()
{
if (!(this is INSCopying)) throw new InvalidOperationException ("Type does not conform to NSCopying");
NSObject? ret;
if (IsDirectBinding) {
ret = Runtime.GetNSObject (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, Selector.GetHandle ("copy")))!;
} else {
ret = Runtime.GetNSObject (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.SuperHandle, Selector.GetHandle ("copy")))!;
}
if (ret != null)
global::ObjCRuntime.Messaging.void_objc_msgSend (ret.Handle, Selector.GetHandle ("release"));
return ret!;
} so since it checks if the current type implements INSCopying, it seems you need to implement the INSCopying interface in your binding. |
Any updates on this one? (going through our bindings script and checking links for updates). Updating bindings is extremely difficult |
I've just implemented a fix for this. It might take a little while until it's released though (at the very latest it'll be with .NET 9 later in the fall). |
Scratch that, I got confused with #17109 and posted here instead of in #17109. |
Thanks @rolfbjarne. Will this land on .NET 9? |
Yes, this will be included in .NET 9. |
Steps to Reproduce
dotnet new iosbinding -n MyBindingProject
ApiDefinition.cs
to:dotnet build
Expected Behavior
Compiles without warnings, and generated
Widget
class contains:Actual Behavior
Gives CS8767 warning:
Generated
Widget
class contains:... and its implementation (in
Widget.g.cs
) assumeszone
is non-nullable, so will throw when passed a null.Environment
Version information
Build Logs
msbuild.binlog.zip
Example Project
MyBindingProject.zip
The text was updated successfully, but these errors were encountered: