internal bool Compile(bool throwOnFileNotFound){
try{
String assemblyFileName = Path.GetFileName(this.assemblyName);
String alternateName = assemblyFileName + ".dll";
if (String.Compare(assemblyFileName, "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0 ||
String.Compare(alternateName, "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0)
this.assembly = typeof(Object).Assembly;
if (String.Compare(assemblyFileName, "microsoft.jscript.dll", StringComparison.OrdinalIgnoreCase) == 0 ||
String.Compare(alternateName, "microsoft.jscript.dll", StringComparison.OrdinalIgnoreCase) == 0) {
this.assembly = engine.JScriptModule.Assembly;
} else if (String.Compare(assemblyFileName, "microsoft.vsa.dll", StringComparison.OrdinalIgnoreCase) == 0 ||
String.Compare(alternateName, "microsoft.vsa.dll", StringComparison.OrdinalIgnoreCase) == 0) {
this.assembly = engine.VsaModule.Assembly;
} else if (this.engine.ReferenceLoaderAPI != LoaderAPI.ReflectionOnlyLoadFrom) {
if (String.Compare(assemblyFileName, "system.dll", StringComparison.OrdinalIgnoreCase) == 0 ||
String.Compare(alternateName, "system.dll", StringComparison.OrdinalIgnoreCase) == 0)
this.assembly = typeof(System.Text.RegularExpressions.Regex).Module.Assembly;
}
if (this.assembly == null) {
String path = this.engine.FindAssembly(this.assemblyName);
// if not found, look for the file with ".dll" appended to the assembly name
if (path == null){
// check for duplicates before we add the ".dll" part
alternateName = this.assemblyName + ".dll";
bool fDuplicate = false;
foreach (Object item in this.engine.Items){
if (item is VsaReference && String.Compare(((VsaReference)item).AssemblyName, alternateName, StringComparison.OrdinalIgnoreCase) == 0){
fDuplicate = true;
break;
}
}
if (!fDuplicate){
path = this.engine.FindAssembly(alternateName);
if (path != null)
this.assemblyName = alternateName;
}
}
if (path == null){
if (throwOnFileNotFound)
throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, new System.IO.FileNotFoundException());
else
return false;
}
switch (this.engine.ReferenceLoaderAPI) {
case LoaderAPI.LoadFrom: this.assembly = Assembly.LoadFrom(path); break;
case LoaderAPI.LoadFile: this.assembly = Assembly.LoadFile(path); break;
case LoaderAPI.ReflectionOnlyLoadFrom: this.assembly = Assembly.ReflectionOnlyLoadFrom(path); break;
}
// Warn if building a machine specfic assembly and the referenced assembly is machine
// specific but does not match.
CheckCompatibility();
}
}catch(VsaException){
throw;
}catch(System.BadImageFormatException e){
throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, e);
}catch(System.IO.FileNotFoundException e){
if (throwOnFileNotFound)
throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, e);
else
return false;
}catch(System.IO.FileLoadException e){
throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, e);
}catch(System.ArgumentException e){
throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, e);
}catch(Exception e){
throw new VsaException(VsaError.InternalCompilerError, e.ToString(), e);
}catch{
throw new VsaException(VsaError.InternalCompilerError);
}
if (this.assembly == null){
if (throwOnFileNotFound)
throw new VsaException(VsaError.AssemblyExpected, this.assemblyName);
else
return false;
}
return true;
}