From 687fe4567252f5f9b24f0b8207386b2a2b72063a Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Mon, 6 Dec 2010 10:28:37 -0800 Subject: [PATCH] Fix dynamic compilation issue Don't try to load references that have been already loaded by extension loaders. This bug was affecting compiling of modules depending on other modules (e.g. Orchard.Widgets depends on Orchard.Scripting). If Orchard.Scripting has been loaded by the dynamic compilation loader, don't try to load the "Orchard.Scripting" assembly. --HG-- branch : dev --- .../Compilers/DefaultExtensionCompiler.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Orchard/Environment/Extensions/Compilers/DefaultExtensionCompiler.cs b/src/Orchard/Environment/Extensions/Compilers/DefaultExtensionCompiler.cs index 9b8141fae..a999b5567 100644 --- a/src/Orchard/Environment/Extensions/Compilers/DefaultExtensionCompiler.cs +++ b/src/Orchard/Environment/Extensions/Compilers/DefaultExtensionCompiler.cs @@ -58,33 +58,45 @@ namespace Orchard.Environment.Extensions.Compilers { context.AssemblyBuilder.AddCodeCompileUnit(CreateCompileUnit(filename)); } + var addedReferences = new HashSet(StringComparer.OrdinalIgnoreCase); + // Add assembly references foreach (var reference in dependencyDescriptor.References) { var referenceTemp = reference; var loader = _loaders.SingleOrDefault(l => l.Name == referenceTemp.LoaderName); - if (loader != null) { - var assembly = loader.LoadReference(reference); - if (assembly != null) { - context.AssemblyBuilder.AddAssemblyReference(assembly); - } + if (loader == null) { + Logger.Warning("Could not find loader '{0}' in active loaders", reference.LoaderName); + continue; } + + var assembly = loader.LoadReference(reference); + if (assembly == null) { + Logger.Warning("Loader '{0}' could not load reference '{1}'", reference.LoaderName, reference.Name); + continue; + } + + addedReferences.Add(reference.Name); + context.AssemblyBuilder.AddAssemblyReference(assembly); } - // Load references specified in project file + // Load references specified in project file (only the ones not yet loaded) foreach (var assemblyReference in projectFileDescriptor.References) { + if (addedReferences.Contains(assemblyReference.SimpleName)) + continue; + var assembly = _assemblyLoader.Load(assemblyReference.FullName); if (assembly != null) { context.AssemblyBuilder.AddAssemblyReference(assembly); } else { - Logger.Warning("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath); + Logger.Error("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath); throw new OrchardCoreException(T( "The assembly reference '{0}' could not be loaded.\r\n\r\n" + "There are generally a few ways to solve this issue:\r\n" + "1. Remove the assembly reference from the project file if it's not needed.\r\n" + "2. Ensure the assembly reference is present in the 'bin' directory of the module.\r\n" + "3. Ensure the assembly reference is present in the 'bin' directory of the application.\r\n" + - "4. Specify the strong name of the assembly (name, version, culture, publickey) if the assembly is present in the GAC.", + "4. Specify the strong name of the assembly (name, version, culture, publickey) if the assembly is present in the GAC.", assemblyReference.FullName)); } }