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 binding to NSString returns null #20061

Closed
akravch opened this issue Feb 8, 2024 · 3 comments · Fixed by #20066
Closed

.NET 8 iOS binding to NSString returns null #20061

akravch opened this issue Feb 8, 2024 · 3 comments · Fixed by #20066
Labels
bug If an issue is a bug or a pull request a bug fix
Projects
Milestone

Comments

@akravch
Copy link

akravch commented Feb 8, 2024

Steps to Reproduce

  1. Get a static .a library that has an NSString field in code: NSString *Foo = @"Bar";.

  2. Create an iOS binding project that binds to the static lib and to the field:

     [Static]
     interface Constants
     {
         // extern NSString * Foo;
         [Field("Foo", "__Internal")]
         NSString Foo { get; }
     }
  3. Create a .NET 8 iOS project that would reference the binding project.

  4. Log Constants.Foo.

Expected Behavior

Constants.Foo returns "Bar".

Actual Behavior

Constants.Foo returns null.

If we change the target framework of the consumer project from .NET 8 to .NET 7, "Bar" is returned as expected. Also, from what I can see, it doesn't matter if the binding project is .NET 7 or .NET 8.

Environment

.NET 8.0.101
iOS workload 17.2.8004/8.0.100
XCode 15.2
iOS Simulator with iOS 17.2
macOS Sonoma 14.3
Apple Silicon M1

Build Logs

log.binlog.zip

Example Project

https://github.com/akravch/IosNet8Binding

I bind to https://github.com/microsoft/plcrashreporter/releases/tag/1.11.1 and log PLCrashReporterException field.

I chose the PLCrashReporter library simply because it was the first thing that came to my mind I could find already compiled, but the behavior is the same regardless of the library.

@rolfbjarne
Copy link
Member

I can reproduce this.

As a workaround you can add this to your consuming csproj:

<PropertyGroup>
    <_ExportSymbolsExplicitly>false</_ExportSymbolsExplicitly>
</PropertyGroup>

@rolfbjarne rolfbjarne added this to the Future milestone Feb 8, 2024
@rolfbjarne rolfbjarne added the bug If an issue is a bug or a pull request a bug fix label Feb 8, 2024
@rolfbjarne rolfbjarne modified the milestones: Future, .NET 9 Feb 8, 2024
@rolfbjarne rolfbjarne added this to Bugs in .NET 9 Feb 8, 2024
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Feb 8, 2024
@akravch
Copy link
Author

akravch commented Feb 14, 2024

I can reproduce this.

As a workaround you can add this to your consuming csproj:

<PropertyGroup>
    <_ExportSymbolsExplicitly>false</_ExportSymbolsExplicitly>
</PropertyGroup>

Apparently it only helps with the simulator build. When I deploy the app the a real device, those fields remain null. It may be a different issue though, because in this case switching to .NET 7 doesn't help either.

Any thoughts on a workarounds that would work for a device?

@rolfbjarne
Copy link
Member

Try adding the following to your csproj:

<PropertyGroup>
    <_ExportSymbolsExplicitly>false</_ExportSymbolsExplicitly>
    <NoSymbolStrip>true</NoSymbolStrip>
</PropertyGroup>
<ItemGroup>
    <_MainLinkerFlags Include="-u" />
    <_MainLinkerFlags Include="_PLCrashReporterException" />
</ItemGroup>

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
2 participants