Author: brett
Date: Mon Aug 22 08:39:17 2011
New Revision: 1160144

URL: http://svn.apache.org/viewvc?rev=1160144&view=rev
Log:
[NPANDAY-445] avoid loading from path so that reference assemblies don't cause 
a conflict in the main appdomain

Modified:
    
incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/NPanday/VisualStudio/Addin/Connect.cs

Modified: 
incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/NPanday/VisualStudio/Addin/Connect.cs
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/NPanday/VisualStudio/Addin/Connect.cs?rev=1160144&r1=1160143&r2=1160144&view=diff
==============================================================================
--- 
incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/NPanday/VisualStudio/Addin/Connect.cs
 (original)
+++ 
incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/NPanday/VisualStudio/Addin/Connect.cs
 Mon Aug 22 08:39:17 2011
@@ -852,17 +852,20 @@ namespace NPanday.VisualStudio.Addin
                     }
                     else
                     {
-                        Assembly a = 
Assembly.ReflectionOnlyLoadFrom(pReference.Path);
+                        // Because this might be a "reference assembly", which 
is a copy in a new location,
+                        // we can't just load it from the path - so try to 
find it in the GAC
+                        List<string> refs = 
GacUtility.GetInstance().GetAssemblyInfo(pReference.Name, pReference.Version, 
null);
 
-                        // original is probably a reference assembly, so now 
check if it's in the GAC
-                        // for that, we must load (runtime) instead of just 
reflection, or from the reference path
-                        AppDomain appDomain = 
AppDomain.CreateDomain("NPandayTempDomain");
-                        Assembly asm = appDomain.Load(a.FullName);
-                        if (asm.GlobalAssemblyCache)
+                        Assembly a = null;
+
+                        if (refs.Count > 0)
+                        {
+                            a = Assembly.ReflectionOnlyLoad(new 
System.Reflection.AssemblyName(refs[0]).FullName);
+                        }
+ 
+                        if (a != null)
                         {
-                            // use the original assembly to get the GAC type 
so we don't get the wrong image version
-                            // but use processor architecture from the GAC 
version as it is None otherwise
-                            refType = 
GacUtility.GetNPandayGacType(a.ImageRuntimeVersion, 
asm.GetName().ProcessorArchitecture, refToken);
+                            refType = 
GacUtility.GetNPandayGacType(a.ImageRuntimeVersion, 
a.GetName().ProcessorArchitecture, refToken);
                         }
                         else
                         {
@@ -878,7 +881,6 @@ namespace NPanday.VisualStudio.Addin
                              ), "Add Reference", MessageBoxButtons.OK, 
MessageBoxIcon.Warning);
                             }
                         }
-                        AppDomain.Unload(appDomain);
                     }
                 }
                 else


Reply via email to