xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.45k stars 511 forks source link

Error "The type 'NSObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'Xamarin.iOS, Version=0.0.0.0" #20570

Closed PureWeen closed 4 months ago

PureWeen commented 4 months ago

Issue moved from dotnet/maui#22021


From @navkumar401 on Wednesday, April 24, 2024 4:26:12 AM

0

In my iOS MAUI project, I'm getting an error "The type 'NSObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'" for references that are referring to a Binding Project that has been upgraded to Microsoft.iOS framework.

I can see that the Binding Project is referencing Microsoft.iOS in the decoded DLL but still, the iOS project is throwing the above error for Xamarin.iOS.

I couldn't find much help online and being stuck with this for a long time, any help would be great.

PureWeen commented 4 months ago

Issue moved from dotnet/maui#22021


From @drasticactions on Thursday, April 25, 2024 5:40:24 AM

CC @rolfbjarne

Can you make a repro project for how you're setting up your binding projects? my guess is that you're directly referencing the binding project to your app, which I believe won't work. You would either need to package your library into a nuget, or reference the outputted DLL from the project, not the project itself.

PureWeen commented 4 months ago

Issue moved from dotnet/maui#22021


From @navkumar401 on Thursday, April 25, 2024 10:19:24 AM

I am referencing the binding project as a DLL only. As you said, it will not work as a project reference.

Another weird thing is that the IntelliSense is not working properly on the binding project. I cannot see what package of iOS (Xamarin.iOS or Microsoft.iOS) the "Foundation" namespace refers to. But since the binding project is referencing Microsoft.iOS physically, I can see the same in the output DLL.

I have uploaded a piece of code from the binding project here

I could not get the sample iOS project (I will continue to try) but we're getting the error in question if we use any type (from the binding project dll. ex: UPCA) in the iOS project.

rolfbjarne commented 4 months ago

I am referencing the binding project as a DLL only. As you said, it will not work as a project reference.

Is the main project a .NET project or a Xamarin project?

rmorin04 commented 4 months ago

Any updates?

navkumar401 commented 4 months ago

It's a .Net project.

Anyway, I had to create a new project again and copy over the files. It worked there. This thread can be closed. Thanks to all who responded.