Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Crashes on UWP when .NET Native compiled #92

Closed
andrewleader opened this issue Feb 23, 2023 · 2 comments
Closed

Crashes on UWP when .NET Native compiled #92

andrewleader opened this issue Feb 23, 2023 · 2 comments

Comments

@andrewleader
Copy link

After updating to 6.0.0 (I think it started with 6.0.0), I get the following exception when calling TZNames.GetDisplayNames() when my app is compiled with .NET Native (works fine in debug without .NET Native).

TimeZoneData.Load ()
System.Reflection.MissingMetadataException: This operation cannot be carried out because metadata for the following object was removed for performance reasons:\n\n EETypeRva:0x00003130\n\nNo further information is available. Rebuild in debug mode for better information.

This seems to be because TimeZoneNames is now using System.Text.Json, which seems to have problems with UWP .NET Native currently: dotnet/runtime#978

Workaround

As described in dotnet/runtime#978 (comment), in your UWP app's Properties/Default.rd.xml file, add the following namespace line for System.Text.Json.Serialization.Converters

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>

    <Assembly Name="*Application*" Dynamic="Required All" />
    
    
    <!-- Add your application specific runtime directives here. -->
	  
	<!-- Fix System.Text.Json 4.7.0 getting compiled out: https://github.com/dotnet/runtime/issues/978-->
	<Namespace Name="System.Text.Json.Serialization.Converters" Dynamic="Required All"/>


  </Application>
</Directives>

Hope that helps some folks with the same issue! I think it could be possible for TimeZoneNames to include this declarative on behalf of System.Text.Json, but the right fix would be for Microsoft to fix that in the Json package itself. So I'm mostly posting this just as info for other users, feel free to close this if you'd like!

@mattjohnsonpint
Copy link
Owner

Yeah, I've seen such things before with other projects. I don't publish a UWP-specific target though, so I don't think there's much I can do in this library. Thanks for sharing a workaround though! 👍

@mattjohnsonpint
Copy link
Owner

FYI - the other place I saw this was getsentry/sentry-dotnet#2029, and actually I believe it also may be due to STJ. Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants