10

I'm trying to make my app (for Windows 10) working under .NET native.

I got stuck with the following issue: Enum.GetValues fails at runtime with metadata is missing. I managed to simplify test case for this problem (in real life my code looks different). In portable library I have:

public enum enumValues
{        
    A1,     
    B1,        
    C1,
}

public class fff
{
    public static object GetClass2Value()
    {
        return enumValues.B1;
    }
}

In my Universal Windows app I call the following code:

Array aaa = Enum.GetValues(fff.GetClass2Value().GetType());

I receive the following exception:

Additional information: 'enumlibportable.enumValues[]' is missing metadata.

The problem is that I have no idea what to add to Default.rd.xml. I've tried to add different rd strings (enum subtype, enumValues class, enumValues[] etc.) using microsoft tool http://go.microsoft.com/fwlink/?LinkID=392859, but had no luck.

UPDATE: I know that the following code will work for my testcase Enum.GetValues(typeof(enumValue)), but I can't use it in my real project since I don't know the exact enum type in my real project.

Access Denied
  • 8,723
  • 4
  • 42
  • 72
  • I assume the real code is a subclassing/interface case? Can you please elaborate on that a bit? – Nyerguds Sep 08 '15 at 08:35
  • Well, it's too long to explain my real project, that's why I spend lot of time finding the cause of the problem and preparing sample. I described well enough my problem. The problem is that optimization deletes enum metadata since it's not referenced in application explicitly. I need to tell compiler not to delete this metadata. – Access Denied Sep 08 '15 at 08:49
  • Can't you make the return type generic? – Stefan Over Sep 08 '15 at 08:55

2 Answers2

5

It doesn't make sense to me, but the following RD string worked for my testcase:

<Type Name="enumlibportable.enumValues[]" Browse="Required All"/>
Access Denied
  • 8,723
  • 4
  • 42
  • 72
  • One thing that is useful is to use the overly generous directive: . This will make all of the types in your application have enough information so that reflection of this type will work. It works so well, it's included in the blank UWP template under Properties\Default.rd.xml! HTH – MattWhilden Nov 23 '15 at 22:09
  • I found this line in my project, it was there and it does not work in my case. I suspect this is a bug in .NET native. – Access Denied Nov 24 '15 at 09:54
0

May be you can try this might help you

Array aaa = (enumValues) Enum.Parse(typeof(enumValues), fff.GetClass2Value());
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • In my real project I don't know the exact type and it could be different enum types, I can't use this approach, unfortunately. And this is not a proper solution, I think. If I add some new enum I will have to add this workaround for each enum. This should be done somehow through runtime definitions. – Access Denied Sep 08 '15 at 08:18