jeudi 24 juin 2021

Using System.Reflection.Emit in UWP (with .NET Native Tool Chain)

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?





Aucun commentaire:

Enregistrer un commentaire