A
Andrus
I need compile in-memory assembly which references to other in-memory
assembly.
Compiling second assembly fails with error
Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' could not be found
Saving assembly to Windows temp directory for referencing only creates huge
amout of temporary
files. I don't know any way to delete those files since they are locked by
loaded assemblies.
Creating separate Appdomain causes issues when I want to pass my
application types.
How to fix ?
Is is possible/reasonabe to compile assembly twice: one compile to memory
and second compile to temporary directory for reference only ?
Or is it possible to delete those temporary files ?
Andrus.
using System;
using System.CodeDom.Compiler;
using System.Windows.Forms;
class Program {
static void Main() {
Microsoft.CSharp.CSharpCodeProvider provider = new
Microsoft.CSharp.CSharpCodeProvider();
CompilerParameters compilerParameters = new CompilerParameters {
GenerateInMemory = true
};
CompilerResults compilerResults =
provider.CompileAssemblyFromSource(compilerParameters, "public
class Test {}");
if (compilerResults.Errors.HasErrors)
throw new ApplicationException("Unexpected compile error");
var asm1 = compilerResults.CompiledAssembly;
compilerParameters.ReferencedAssemblies.Add(asm1.FullName);
compilerResults =
provider.CompileAssemblyFromSource(compilerParameters, "public
class Test1 : Test {}");
if (compilerResults.Errors.HasErrors) {
string msg;
msg = compilerResults.Errors.Count.ToString() + " Errors:";
for (int x = 0; x < compilerResults.Errors.Count; x++)
msg = msg + "\r\nLine: " +
compilerResults.Errors[x].Line.ToString() + " - " +
compilerResults.Errors[x].ErrorText;
//Causes Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0,
Culture=neutral,
//PublicKeyToken=null' could not be found
MessageBox.Show(msg);
}
}
}
assembly.
Compiling second assembly fails with error
Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' could not be found
Saving assembly to Windows temp directory for referencing only creates huge
amout of temporary
files. I don't know any way to delete those files since they are locked by
loaded assemblies.
Creating separate Appdomain causes issues when I want to pass my
application types.
How to fix ?
Is is possible/reasonabe to compile assembly twice: one compile to memory
and second compile to temporary directory for reference only ?
Or is it possible to delete those temporary files ?
Andrus.
using System;
using System.CodeDom.Compiler;
using System.Windows.Forms;
class Program {
static void Main() {
Microsoft.CSharp.CSharpCodeProvider provider = new
Microsoft.CSharp.CSharpCodeProvider();
CompilerParameters compilerParameters = new CompilerParameters {
GenerateInMemory = true
};
CompilerResults compilerResults =
provider.CompileAssemblyFromSource(compilerParameters, "public
class Test {}");
if (compilerResults.Errors.HasErrors)
throw new ApplicationException("Unexpected compile error");
var asm1 = compilerResults.CompiledAssembly;
compilerParameters.ReferencedAssemblies.Add(asm1.FullName);
compilerResults =
provider.CompileAssemblyFromSource(compilerParameters, "public
class Test1 : Test {}");
if (compilerResults.Errors.HasErrors) {
string msg;
msg = compilerResults.Errors.Count.ToString() + " Errors:";
for (int x = 0; x < compilerResults.Errors.Count; x++)
msg = msg + "\r\nLine: " +
compilerResults.Errors[x].Line.ToString() + " - " +
compilerResults.Errors[x].ErrorText;
//Causes Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0,
Culture=neutral,
//PublicKeyToken=null' could not be found
MessageBox.Show(msg);
}
}
}