c# - Why am I unable to do an Assembly.Load of WinMD files? -


i'm trying write method of namespaces assembly/winmd file c#. reason, i'm having trouble doing winmd files because i'm unable load them. here relevant portion code (partially stolen this answer reflecting on winmds):

using system; using system.linq; using system.reflection; using system.runtime.interopservices.windowsruntime;  public static class load {     public static assembly assemblyfrom(string path)     {         var domain = appdomain.currentdomain;         resolveeventhandler assemblyhandler = (o, e) => assembly.reflectiononlyload(e.name);         eventhandler<namespaceresolveeventargs> namespacehandler = (o, e) =>         {             string file = windowsruntimemetadata                 .resolvenamespace(e.namespacename, array.empty<string>())                 .firstordefault();              if (file == null)                 return;              var assembly = assembly.reflectiononlyloadfrom(file);             e.resolvedassemblies.add(assembly);         };          try         {             // load it! (plain .net assemblies)             return assembly.loadfrom(path);         }         catch         {             try             {                 // hook handlers                 domain.reflectiononlyassemblyresolve += assemblyhandler;                 windowsruntimemetadata.reflectiononlynamespaceresolve += namespacehandler;                  // load again! (winmd components)                 return assembly.reflectiononlyloadfrom(path);             }                         {                 // detach handlers                 domain.reflectiononlyassemblyresolve -= assemblyhandler;                 windowsruntimemetadata.reflectiononlynamespaceresolve -= namespacehandler;             }         }     } } 

for reason, looks winmd files failing, both regular , reflection-only assembly loads i'm attempting. when try assembly.loadfrom on exception saying it's not supported (which to expected). then, when try reflection-only method, exception (specifically, reflectiontypeloadexception). when catch , print loaderexceptions property, this:

try {     // add handlers      return assembly.reflectiononlyloadfrom(path); } catch (reflectiontypeloadexception e) {     foreach (var inner in e.loaderexceptions)         console.writeline(inner); } {     // remove handlers } 

i whole bunch of error spew in console, this:

neither of handlers (assemblyhandler nor namespacehandler) i've added seem getting called, either; when add console.writelines them, never see output on screen.

can tell me why happening , how fix it? greatly appreciated, since i've been banging head on 2 days.


edit: i've made full output available github gist here.


edit 2: if have windows 10 dev tools installed, can try running method on

c:\program files (x86)\windows kits\10\references\windows.foundation.universalapicontract\2.0.0.0\windows.foundation.universalapicontract.winmd 

to repro.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -