469,962 Members | 2,885 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,962 developers. It's quick & easy.

Failures with dynamic in-memory assembly generation

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

Nov 17 '05 #1
0 953

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Timo Virkkala | last post: by
2 posts views Thread by Jeff Smith | last post: by
14 posts views Thread by Spare Change | last post: by
reply views Thread by db2sysc | last post: by
15 posts views Thread by Nak | last post: by
7 posts views Thread by Connie | last post: by
158 posts views Thread by jacob navia | last post: by
6 posts views Thread by =?Utf-8?B?TmljayBCdXJraXR0?= | last post: by
2 posts views Thread by Damir | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.