0

I have a partial assembly name, e.g., "PresentationUI". How can I resolve and load this partial assembly name into the reflection-only context.

// THIS GETS AN EXCEPTION
Assembly.ReflectionOnlyLoad("PresentationUI");  

// THIS GETS AN EXCEPTION (AND IS NOT REFLECTION-ONLY)
Assembly.Load("PresentationUI");                

// THIS WORKS (BUT IS OBSOLETE AND IS NOT REFLECTION-ONLY)
Assembly.LoadWithPartialName("PresentationUI");

The exceptions mentioned above are the same in either case:

FileNotFoundException: Could not load file or assembly 'PresentationUI' or one of its dependencies. The system cannot find the file specified.

I have tried using AppDomain.CurrentDomain.ApplyPolicy() in an attempt to resolve the partial assembly name to a full assembly name, but no luck.

// THIS RETURNS "PresentationUI"
AppDomain.CurrentDomain.ApplyPolicy("PresentationUI");
Brian Knoblauch
  • 20,639
  • 15
  • 57
  • 92
Michael Gunter
  • 12,528
  • 1
  • 24
  • 58
  • Also add info on what is the full name of the assembly and where it is located. – Alexei Levenkov Jun 11 '14 at 20:02
  • @Alexei: Doesn't seem to matter. – Michael Gunter Jun 11 '14 at 20:05
  • IIRC, you need to help it load every dependency for ReflectionOnlyLoad. – SLaks Jun 11 '14 at 20:05
  • @SLaks: I'll triple-check, but I believe I'm already doing that. I have already accomplished all this reflection-only stuff for full names. – Michael Gunter Jun 11 '14 at 20:06
  • InvalidOperationException or FileNotFound? – Mare Infinitus Jun 11 '14 at 20:06
  • What does not matter? If file is not in default probing path normal Load will not be able to find it. Look at fusion log to see waht it actually doing. – Alexei Levenkov Jun 11 '14 at 20:07
  • The file is actually in the GAC. – Michael Gunter Jun 11 '14 at 20:08
  • @SLaks: In this case, my `ReflectionOnlyAssemblyResolve` handler isn't being called. – Michael Gunter Jun 11 '14 at 20:09
  • @MareInfinitus: FileNotFoundException. But please note that only 2 of the calls in the post get this exception. The assembly is present -- it's in the GAC. It's just that ReflectionOnlyLoad() and Load() don't like the partial name. – Michael Gunter Jun 11 '14 at 20:11
  • Can you use the LoadWithPartialName() first to get the full signature of the module, and then use the reflection-only version? Which will hopefully work when given the full signature. To avoid the first load remaining loaded and confusing the situation you'll have to do that load in a separate process or a separate AppDomain. – RenniePet Jun 11 '14 at 20:33
  • @RenniePet: This would work for some scenarios, but I really can't do a non-reflection-only load. – Michael Gunter Jun 11 '14 at 20:36
  • Hmmm, my knowledge is very limited here. But is it correct that if you did have the full signature (display name) of the module then ReflectionOnlyLoad would be OK? If so, can you read the GAC to determine that information? A couple of links that might help: http://stackoverflow.com/questions/1933947/check-gac-for-an-assembly http://www.codeproject.com/Articles/4352/Demystifying-the-NET-Global-Assembly-Cache – RenniePet Jun 11 '14 at 20:50
  • The assembly won't always be in GAC. Sometimes it will, sometimes it will not. I have no control over the input assembly to this procedure. I'm digging through these docs to get additional info: http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx – Michael Gunter Jun 11 '14 at 20:52
  • @MichaelGunter- Did you ever get this problem solved? I'm facing the same issue when trying to load "WindowsBase" whihc it should load from GAC. It works with LoadWithPartialName but again that's obsolete. any thoughts? – jamilia Jan 19 '21 at 02:13
  • @jamilia No, I had no luck. And I forget now how I worked around it for my use case. My original issue was on .NET 4.0, I believe. I have no idea if the issue still exists on .NET Core or anything – Michael Gunter Jan 19 '21 at 17:24
  • Thanks @MichaelGunter for responding. I managed to get the full assembly name as I had reference to both type and assembly name. I got the type like, Type type= Type.GetType("System.Windows.Rect, WindowsBase"); string fullassemblyName = type.Assembly.FullName.ToString(); Assembly.Load(fullassemblyName ); But not sure how to attain when one has just the partial assembly name – jamilia Jan 22 '21 at 19:15

0 Answers0