0

I have UWP code which is working with System.Reflection.Module type. When the app is compiled in DEBUG mode all is ok and I can get custom attributes for the module. But when I switch to RELEASE mode and compile the app with .NET Native all those attributes disappear.

ger18s
  • 57
  • 4

2 Answers2

4

After your application is run through the .Net Native tool chain (ilc.exe) you'll notice that your application binaries don't appear as you'd naively expect. This is because all of your .Net code (including the piece of the .Net Framework your app requires) has been folded into a single binary .dll. We do this because many optimization steps work much better when the compiler can view the entire state of your program. It also can speed up your start time because finding a bunch of different files on disk isn't on the hot path.

Given all of the above, it was necessary to come up with a policy for Assembly attributes. In the end, it was easier to eliminate support than to figure out a way to get conflicting things to mesh nicely.

If you have a scenario that is only possible through these attributes we'd love to know more about it.

MattWhilden
  • 1,686
  • 13
  • 18
  • I had some code which relied on this attribute. I am now using another approach. Thank you! – ger18s Nov 23 '15 at 09:31
  • @Matt: Can you clarify this answer? I.e. can you confirm that this is _only_ for assembly-level attributes, and that attributes on types and members still are supported and work as expected? – Peter Duniho Oct 14 '16 at 19:01
  • We expect all other attributes to work exactly as usual. We retain full metadata information about where they are applied, generate code for any constructors they may have etc. As always, if you have any trouble please shoot me a mail at dotnetnative@microsoft.com. Happy to help. – MattWhilden Oct 18 '16 at 02:40
1

Please check these links:

Reflection and .NET Native

NET Native Deep Dive: Help! I Hit a MissingMetadataException

You can probably fix this issue by updating the .rd.xml (Runtime Directives Configuration File) as explained in the previous article.

And for information :

Runtime Directives (rd.xml) Configuration File Reference

  • The problem I have is that in the same time I can get custom attributes for assembly (without any modifications). So [module: MyAttribute] doesn't work but [assembly: MyAttribute] works just fine. – ger18s Nov 16 '15 at 12:15