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

CoreRT support #10

Closed
tjm00 opened this issue Aug 3, 2018 · 9 comments
Closed

CoreRT support #10

tjm00 opened this issue Aug 3, 2018 · 9 comments

Comments

@tjm00
Copy link

tjm00 commented Aug 3, 2018

Does coreRT support fall within this project's goal of portability? Running a console program compiled with coreRT that uses this library results in an unhandled System.TypeInitializationException. It looks like it is related to reflection, somewhere around Org.BouncyCastle.Utilities.Enums.GetArbitraryValue(Type), but the error was a bit more obscure than usual so I haven't dug to far into it.

@clairernovotny
Copy link
Collaborator

It should work there, though errors are likely on the CoreRT side as this is a netstandard2.0 library. If you can provide a repro, I can raise it with the right team.

@tjm00
Copy link
Author

tjm00 commented Aug 3, 2018

It looks like this one-liner is sufficient to reproduce it: X9ECParameters bcCurve = NistNamedCurves.GetByName("P-521");.

@clairernovotny
Copy link
Collaborator

Is there a minimal project you could zip up and attach here (or a repo you can point to)?

@tjm00
Copy link
Author

tjm00 commented Aug 3, 2018

This does it for me.

@clairernovotny
Copy link
Collaborator

Thanks, looking into where the issue goes.

@MichalStrehovsky
Copy link

The best way to report CoreRT issues is to report them in the CoreRT repo, along with the stack trace and full exception information (we might not even have to spend time reproing this because some stacks are pretty obvious).

The stack trace for this one is:

Unhandled Exception: System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property. ---> System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property. ---> System.Reflection.MissingMetadataException: 'Org.BouncyCastle.Security.DigestUtilities.DigestAlgorithm[]' is missing metadata. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=392859
   at CorertRepro!<BaseAddress>+0x37596
   at CorertRepro!<BaseAddress>+0x9053a
   at CorertRepro!<BaseAddress>+0x155979
   at CorertRepro!<BaseAddress>+0x37311
   at CorertRepro!<BaseAddress>+0x53925
   at System.Enum.GetValues(Type) + 0xb4
   at Org.BouncyCastle.Utilities.Enums.GetArbitraryValue(Type) + 0x9
   at CorertRepro!<BaseAddress>+0x819dd
   at CorertRepro!<BaseAddress>+0x13c890

This is an Enum.GetValues call trying to get values for a specific enum, but the AOT compiler didn't know we would need to generate code for the array of the enum. There are multiple ways to fix this:

  • Include a static reference to Org.BouncyCastle.Security.DigestUtilities.DigestAlgorithm[] somewhere (new up the array in code). That way we'll be able to find the code at runtime.
  • If your code doesn't rely on the semantic of Enum.GetValues returning a precise instance of the enum array, you can specify <AppContextSwitchOverrides Include="Switch.System.Enum.RelaxedGetValues" /> in one of the ItemGroups of your project. This will cause Enum.GetValues to return an array of the underlying type (so int[]), which is more likely to be available. (You'll see casting problems if the code takes dependency on this undocumented behavior.)
  • Use attached default.rd.zip and add it to your project as <RdXmlFile Include="default.rd.xml" /> in one of your ItemGroups

@clairernovotny
Copy link
Collaborator

The CoreRT repo is here: https://github.com/dotnet/corert/issues

Thanks for chiming in @MichalStrehovsky!

@clairernovotny
Copy link
Collaborator

Closed as external

@tjm00
Copy link
Author

tjm00 commented Aug 9, 2018

Thank you both.

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

No branches or pull requests

3 participants