Why I cannot reference iOS binding library

Wei Wen 1,121 Reputation points
2024-08-20T12:33:07.19+00:00

I created a .net8 MAUI project and an Android and an iOS binding libraries. I can see that in the iOS binding library, the generated classes are created. There are also no errors. But when I tried to reference the classes in the iOS binding library in the MAUI project's iOS Platform, the classes couldn't be recognized. Namespace reference was marked with error. The Android binding library worked fine though.

What did I do wrong on the iOS binding library?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,409 questions
{count} vote

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 30,666 Reputation points Microsoft Vendor
    2024-09-10T06:06:43.5633333+00:00

    Hello,

    I noticed that you have raised an issue at GitHub- ios binding library with xcframework/framework cannot be referenced in the main .NET MAUI project · Issue #21189 · xamarin/xamarin-macios (github.com)

    And you have resolved the problem, I made an answer so that someone with the same issue can refer to it.

    It's only intellisense that doesn't work, if you build the project, it'll build just fine. Referencing the binding project directly, something like this from your main project, should work though:

    <ItemGroup Condition=" '$(TargetPlatformIdentifier)' == 'ios' "> <Reference Include="../MauiDemoApp.Binding.iOS/bin/Debug/net8.0-ios/Com.SAS.CI360.dll" /> </ItemGroup>
    

    Note that in this case you'll have to build the binding project manually first, it won't be built automatically when you're building the main project. Additionally, in your binding project, you should reference the .xcframework (and not the .framework inside the .xcframework):

    <NativeReference Include="SASCollector.xcframework">
    

    Try this:

    <
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


3 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    7 deleted comments

    Comments have been turned off. Learn more

  2. Wei Wen 1,121 Reputation points
    2024-08-22T02:54:24.2233333+00:00

    I think setting TargetFramework in the binding library project file to Xamarin.iOS10 can solve the library namespace and class reference problem. However, if I tried to rebuild the binding library, it would fail saying that "the reference assemblies for Xamarin.iOS10,Version=1.0 were not found", and ask me to install the Developer Pack for this framework version. But I wonder if Xamarin binding library and .NET MAUI project can coexist? Also, in microsoft document on Xamarin binding library migration, it does not say the TargetFramework should be changed to Xamarin.iOS10. Please see the link: https://video2.skills-academy.com/en-us/dotnet/maui/migration/ios-binding-projects?view=net-maui-8.0

    If I only made the binding library's TargetFramework change, and then ran the project, the build was successful, but the app crashed with the reason the library was not loaded (Library missing).

    0 comments No comments

  3. Wei Wen 1,121 Reputation points
    2024-08-22T03:48:31.11+00:00

    I tried setting TargetFramework in the binding library project file to Xamarin.iOS10, and it can solve the library namespace and class reference problem. However, if I tried to rebuild the binding library, it would fail saying that "the reference assemblies for Xamarin.iOS10,Version=1.0 were not found", and ask me to install the Developer Pack for this framework version. But I wonder if .NET MAUI project can include a Xamarin library? Also, in microsoft document on Xamarin binding library migration, it does not say the TargetFramework should be changed to Xamarin.iOS10. Please see the link: https://video2.skills-academy.com/en-us/dotnet/maui/migration/ios-binding-projects?view=net-maui-8.0

    If I only made the binding library's TargetFramework change, and then ran the project, the build was successful, but the app crashed with the reason the library was not loaded.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.