I'm currently working on upgrading a windows 8.1 universal app to a windows 10 UWP app. There is a part of code that was working perfectly before that doesn't work anymore in my Windows 10 UWP app.
I have an enum that looks like this :
public enum EStaticFile
{
[StringValue("Path of a file")]
CONFIG_FILE_1,
[StringValue("Path of a file")]
CONFIG_FILE_2
}
When I try to get the attribute for any of the enum values, it always returns an empty array. I use the following code :
public static StringValue GetStringValueAttribute(this Enum aEnumValue)
{
Type type = aEnumValue.GetType();
FieldInfo fieldInfo = type.GetRuntimeField(aEnumValue.ToString());
StringValue[] attributes = fieldInfo.GetCustomAttributes(typeof(StringValue), false) as StringValue[];
if (attributes.Length > 0)
{
return attributes[0];
}
return null;
}
GetCustomAttributes always returns an empty array, so attributes.Length is always 0, so the function returns null;
Has something changed in Windows 10 that prevent this from working?
Thanks a lot!
I finally found the solution to my problem.
My solution contains C++ projects, so I activated the .Net Native, like it was said in every tutorials I saw about migrating a Windows 8.1 app to a Windows 10 UWP app, which is ok, but doing so sets the property UseDotNetNativeToolChain to true, which causes the problem. To fix the problem, just set it to false everywhere in your faulty project file and it will start working again! And .Net Native still works!
Hope it helps someone!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With