Skip to content
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

.NET 8 IOS Native Binding XcFramework (Static library Wrapper) FAILED #20195

Open
gnibloop opened this issue Feb 25, 2024 · 9 comments
Open

.NET 8 IOS Native Binding XcFramework (Static library Wrapper) FAILED #20195

gnibloop opened this issue Feb 25, 2024 · 9 comments
Labels
bug If an issue is a bug or a pull request a bug fix
Projects
Milestone

Comments

@gnibloop
Copy link

Steps to Reproduce

  1. Create a new Net 8 IOS Application project
  2. Add a IOS Native binding project into same solution and add Native reference of a XcFramework library (Attached zebra printer official SDK which wrap static library for different architecture and platform ), modify the Apidefinition.cs and Structandenums.cs according to sharpie result. Build release.
  3. Add reference of above built assembly into main IOS app project and build and run.

Expected Behavior

The native library should be linked using different platform library and run at all platforms and build configurations.

Actual Behavior

1, when the Binding project's setting set "Static", the project can be built but when running , throw exception of " the native class hasn't been loaded".
2, when the Binding project's setting set "Framework", the project can't build successfully, with a error: "framework not found ios-arm64_x86_64-simulator", Clang++ exit

Environment

Microsoft Visual Studio Professional 2022
Version 17.9.0
VisualStudio.17.Release/17.9.0+34607.119
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Professional

ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.9.195.45391
ASP.NET and Web Tools

Automatic Versions 3.1.1
Provides tools for managing assembly versions.

Azure App Service Tools v3.0.0 17.9.195.45391
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.9.195.45391
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.9.0-3.24081.11+989117396f26e5453ff157df610d22ce45b6b0a9
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.4.39 (main@e8108eb)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.9.0 (b3bca6f)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.9.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.9.2.2408002+5aec2f1744a2273d3e7157cc4cc1986f87f524d4
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.9.51.1
Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 17.0.30103.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.9.0-3.24081.11+989117396f26e5453ff157df610d22ce45b6b0a9
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.9.0-beta.23614.3+a521e1cd420beb56c15faf6836184fadd2b7937a
Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0
Information about my package

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin 17.9.0.138 (d17-9@60c2b9b)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.9.3.0 (remotes/origin/d17-9@f174974f91)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: d9a6e87
Java.Interop: xamarin/java.interop@149d70fe
SQLite: xamarin/sqlite@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools@ca1552d

Build Logs

iOSApp2_Debug_AnyCPU_Build_2024-02-24T18_57_30.6147050-08_00.zip

Example Project (If Possible)

https://github.com/gnibloop/Net8NativeBindingTest

@rolfbjarne
Copy link
Member

I can reproduce the problem.

The correct Kind value is Static, since it's a static library inside the xcframework, but there's a bug preventing things from working.

Can you try adding the following to the test app's csproj to see if it fixes the problem for you?

<ItemGroup>
  <_CustomLinkFlags Include="-u" />
  <_CustomLinkFlags Include="_OBJC_CLASS_$_NetworkDiscoverer" />
  <_CustomLinkFlags Include="-u" />
  <_CustomLinkFlags Include="_OBJC_CLASS_$_PrinterStatus" />
  <_CustomLinkFlags Include="-u" />
  <_CustomLinkFlags Include="_OBJC_CLASS_$_TcpPrinterConnection" />
  <_CustomLinkFlags Include="-u" />
  <_CustomLinkFlags Include="_OBJC_CLASS_$_ZebraPrinterFactory" />
</ItemGroup>

@rolfbjarne rolfbjarne added the bug If an issue is a bug or a pull request a bug fix label Feb 27, 2024
@rolfbjarne rolfbjarne added this to the .NET 9 milestone Feb 27, 2024
@rolfbjarne rolfbjarne added this to Bugs in .NET 9 Feb 27, 2024
@rolfbjarne
Copy link
Member

Note to self:

The problem is that has_linkwith_attributes is false here:

bool has_linkwith_attributes = false;
if (DerivedLinkContext.Target.Assemblies.TryGetValue (type.Module.Assembly, out asm))
has_linkwith_attributes = asm.HasLinkWithAttributes;
if (has_linkwith_attributes) {

The HasLinkWithAttribute property is set here:

HasLinkWithAttributes = true;

but that's not hit, becuase there's a binding resource package for the assembly, so this code path prevents it:

https://github.com/xamarin/xamarin-macios/blob/69bb4ac1fb4dbea862fdc64aacaf600d850620e5/tools/common/Assembly.cs#L162C21-L162C70

@gnibloop
Copy link
Author

I can reproduce the problem.

The correct Kind value is Static, since it's a static library inside the xcframework, but there's a bug preventing things from working.

Can you try adding the following to the test app's csproj to see if it fixes the problem for you?

<ItemGroup>
  <_CustomLinkFlags Include="-u" />
  <_CustomLinkFlags Include="_OBJC_CLASS_$_NetworkDiscoverer" />
  <_CustomLinkFlags Include="-u" />
  <_CustomLinkFlags Include="_OBJC_CLASS_$_PrinterStatus" />
  <_CustomLinkFlags Include="-u" />
  <_CustomLinkFlags Include="_OBJC_CLASS_$_TcpPrinterConnection" />
  <_CustomLinkFlags Include="-u" />
  <_CustomLinkFlags Include="_OBJC_CLASS_$_ZebraPrinterFactory" />
</ItemGroup>

Hi, Thanks for the help. I currently successfully ran the test program. Since we are upgrading a big project form .Net 7 (built by VS Mac), we are facing a lot of same nativebinding library issues. Are we supposed to put all those exposed interface as the same format into project ("OBJ_CLASS.xxxx")? Or should we wait for next patch fix this bug? (when will this fix be available?)

@rolfbjarne
Copy link
Member

Are we supposed to put all those exposed interface as the same format into project ("OBJ_CLASS.xxxx")? Or should we wait for next patch fix this bug? (when will this fix be available?)

I can't say how long it'll take to fix this, so I believe your best approach would be to implement the workaround for all Objective_C interfaces.

@gnibloop
Copy link
Author

Thanks a lot.
Now i moved to another native library binding project with TRUE xcFramework (not static library wrapper). The build was failed with error message such as:

error : clang++ exited with code 1:
error : Undefined symbols for architecture arm64:
error : "_BeginCheckedBlock", referenced from:
error : -exported_symbol[s_list] command line option
error : "_BeginCheckedBlockEx", referenced from:
error : -exported_symbol[s_list] command line option
error : "_ClosePort", referenced from:

Do i need to create another ticket? or this can be fixed by the same solution (adding OBJ reference in csproject itemgroups)?

@rolfbjarne
Copy link
Member

Do i need to create another ticket? or this can be fixed by the same solution (adding OBJ reference in csproject itemgroups)?

Please create a new issue, it may or may not have the same solution, and in case it doesn't, it'll get very confusing here (it's much easier to merge two separate issues than to split one issue in two later on).

@ToolmakerSteve
Copy link

ToolmakerSteve commented May 9, 2024

Do i need to create another ticket? or this can be fixed by the same solution (adding OBJ reference in csproject itemgroups)?

Is this covered by issue #19624? [I think not, since the symptom is different.]

I am having the same problem. .a static library works in a Xamarin.iOS project, but not in a .Net 8 iOS project. Similar error messages with undefined symbols starting with _.

@rolfbjarne
Copy link
Member

Note to self: this might have been fixed with #20479.

@rolfbjarne
Copy link
Member

Do i need to create another ticket? or this can be fixed by the same solution (adding OBJ reference in csproject itemgroups)?

Is this covered by issue #19624? [I think not, since the symptom is different.]

I am having the same problem. .a static library works in a Xamarin.iOS project, but not in a .Net 8 iOS project. Similar error messages with undefined symbols starting with _.

When in doubt, it's always safe to file a new issue :)

It might the be same problem as this issue, but I can't say without a test project I can use to reproduce the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix
Projects
Development

No branches or pull requests

3 participants