AOT not support for unknow type to get value from enum #29975
Replies: 3 comments
-
What exception do you see at runtime? The message in the |
Beta Was this translation helpful? Give feedback.
-
Hi @vitek-karas, No exception is thrown, but the application terminates unexpectedly. In our scenario, the enum type may not be known at compile time, as it is defined in the sample and only discovered through a custom assembly at runtime. Given this, does AOT compilation support such dynamic enum value access at all? Or is there an alternative pattern recommended for safely handling unknown types in AOT environments?. |
Beta Was this translation helpful? Give feedback.
-
You're loading something like "plugins" - that in general is something NativeAOT doesn't really support. If this is more of a discovery framework (some DI frameworks do this), where you go over all assemblies in the app and look for specific types and then use them dynamically, that pattern is also generally not friendly to NativeAOT. A good way to think about this is "If there's something we can't figure at compile time" then it's going to be a problem. Unbounded reflection is a typically case which creates trouble - so calls like |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We have requirement of converting the Enum type class into the Array with the help of following code in the source code.
Enum.GetValues(Type enumType);
since the Enum class is unknow type because it is given in the sample code by the user end like below
[Preverse (All member = true)]
public class Model
{
Public Numbers status {get; set;}
}
[Preverse (All member = true)]
Public Class Numbers
{
Home,
Work,
Other
}
Due to the AOT enable, it does not convert the Array from the Enum and thrown exception.
[RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the GetValues overload or the GetValuesAsUnderlyingType method instead.")]
public static Array GetValues(Type enumType);
Is it possible to get the Enum class into Array of list (Home, Work, Other) without specific the type, since it is know due to given by the customer in the user end.
Beta Was this translation helpful? Give feedback.
All reactions