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
This commit is contained in:
Renaud Paquay
2010-12-06 10:28:37 -08:00
parent 947fb55d7d
commit 687fe45672

View File

@@ -58,33 +58,45 @@ namespace Orchard.Environment.Extensions.Compilers {
context.AssemblyBuilder.AddCodeCompileUnit(CreateCompileUnit(filename)); context.AssemblyBuilder.AddCodeCompileUnit(CreateCompileUnit(filename));
} }
var addedReferences = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
// Add assembly references // Add assembly references
foreach (var reference in dependencyDescriptor.References) { foreach (var reference in dependencyDescriptor.References) {
var referenceTemp = reference; var referenceTemp = reference;
var loader = _loaders.SingleOrDefault(l => l.Name == referenceTemp.LoaderName); var loader = _loaders.SingleOrDefault(l => l.Name == referenceTemp.LoaderName);
if (loader != null) { if (loader == null) {
var assembly = loader.LoadReference(reference); Logger.Warning("Could not find loader '{0}' in active loaders", reference.LoaderName);
if (assembly != null) { continue;
context.AssemblyBuilder.AddAssemblyReference(assembly);
}
} }
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) { foreach (var assemblyReference in projectFileDescriptor.References) {
if (addedReferences.Contains(assemblyReference.SimpleName))
continue;
var assembly = _assemblyLoader.Load(assemblyReference.FullName); var assembly = _assemblyLoader.Load(assemblyReference.FullName);
if (assembly != null) { if (assembly != null) {
context.AssemblyBuilder.AddAssemblyReference(assembly); context.AssemblyBuilder.AddAssemblyReference(assembly);
} }
else { 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( throw new OrchardCoreException(T(
"The assembly reference '{0}' could not be loaded.\r\n\r\n" + "The assembly reference '{0}' could not be loaded.\r\n\r\n" +
"There are generally a few ways to solve this issue:\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" + "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" + "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" + "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)); assemblyReference.FullName));
} }
} }