Hi!
I'm trying to create in-memory assemblies from source using C# 2.0 from
Visual Studio 2005 Beta 2. The generated assembly should have the same
name as an assembly that may already exist on disk in the same directory
the assembly-generating executable is running from.
The code I'm using is as follows:
string Code = "public class PolicyAccess ";
Code += "{ ";
Code += "public void GetPolicy (out string
preferredConnectionType) ";
[...snip...]
CompilerParameters Parameters = new CompilerParameters ();
Parameters.GenerateExecutable = false;
Parameters.GenerateInMemory = true;
Parameters.OutputAssembly = "Dummy.dll";
CodeDomProvider Compiler = CodeDomProvider.CreateProvider
("csharp");
CompilerResults CompResult = Compiler.CompileAssemblyFromSource
(Parameters, new string[] { Code });
Assembly TheAssembly = CompResult.CompiledAssembly;
When I execute this and want to access the CompResult, I either get a
FileNotFoundException in case there is no DLL with the
Parameters.OutputAssembly
name in the directory. Or I get a BadImageFormatException if I just put some
other
file (image, text, etc.) with the required name in the directory. Or, if
some other
assembly with the OutputAssembly name is in the directory, this assembly
gets
loaded, with the types contained in it but not with the types in the Code
string!
In any case I never get to see the type "PolicyAccess" with the method
"GetPolicy".
What is going wrong here??? I was assuming that if one creates an assembly
with
"GenerateInMemory = true" then there would not be any files involved at all.
Is there some "force assembly generation to file" option or something like
that?
Thanks,
Andreas