Reputation: 4308
I have the following code in a UWP app which works fine in Debug mode but throws an exception when compiled in Release / .Net Native.
var type = typeof(IHashCommand);
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(x => type.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
The exception that is thrown is:
System.TypeLoadException: 'The type 'System.Runtime.InteropServices.Marshallers.BaseMarshaller' cannot be found in assembly 'System.Private.Interop, Version=999.999.999.999, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.'
I tried editing the "Default.rd.xml" file and added a namespace node based off of some documentation I found (it didn't work or I'm not setting it up correctly).
<Namespace Name="MudLib.HashCommands" Activate="Required All" Dynamic="Required All" Browse="Required All" />
Effectivly what I'm trying to do is reflect over all the classes in that namespace that implement the IHashCommand interface and then activate them.
Anyone know what I'm missing or have any direction I should go?
Upvotes: 0
Views: 450
Reputation: 66
The problem is, that there is an assembly that is included by .Net Native
. The name of the assemby starts with Hidden. Excluding that assembly will do the trick.
var searchForType = typeof(IHashCommand);
var types = AppDomain.CurrentDomain.GetAssemblies()
.Where(assembly => !assembly.FullName.Contains("Hidden") && !assembly.FullName.Contains("Private"))
.SelectMany(assembly => assembly.GetTypes())
.Where(type => !type.IsInterface && !type.IsAbstract && searchForType.IsAssignableFrom(type));
Upvotes: 2