0

The app that I am working on requires ".NET Native Tool Chain" to be enabled in project settings, as it will be distributed via the Microsoft Store.

Part of the functionality of this app is that it will have calculations performed via a user-defined string (including variables in the string), for example: (5-#myVar#)+2

For this purpose, we are using an expression evaluator to resolve the user-defined calculation string. This library and all equivalent libraries (as far as I can tell) use System.Reflection.Emit to create a DynamicMethod to evaluate the expression.

The problem is with using a DynamicMethod when .NET Native Tool Chain is enabled - a runtime exception occurs: Dynamic code generation is not supported on this platform.

That error makes sense. However, in the app manifest, under "capabilities", there is an option to enable Code Generation. Unfortunately enabling this capability seems to have no effect whatsoever.

Is there something else required to enable code generation? Or is this tickbox a red herring?

And if code generation simply cannot be enabled at all - then is there a workaround for this that would avoid the use of System.Reflection.Emit?

Mike Baxter
  • 6,868
  • 17
  • 67
  • 115
  • https://stackoverflow.com/questions/37857639/create-a-class-dynamically-using-system-reflection-emit-in-uwp – Hans Passant Jun 24 '21 at 12:11
  • Thanks for the link - I did already find that one but I don't think the answer takes .NET Native Tool Chain into account, and the subsequent limitations for distributing to the Microsoft Store. – Mike Baxter Jun 24 '21 at 13:57
  • 1
    I have checked the library, its structure is very complex, these classes use `System.Reflection.Emit` emit the IL language of all elements (filed,method,etc.) and generate dynamic methods many times. If you use this library, there is no way to avoid use `System.Reflection.Emit`. My suggestion is that you use other libraries supported by uwp instead of this, besides, you need to make sure the library works well with .NET Native Tool Chain. – dear_vv Jun 25 '21 at 07:31

0 Answers0