11

I have a CompilerParameters object that I use to feed a Microsoft.CSharp.CSharpCodeProvider object and an ICodeCompiler object that derives from that.

Everything works OK, and I can compile code on the fly. My problem is with the referenced assemblies. Right now, I just add all assemblies from System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies() into the compiler parameter's ReferencedAssemblies. This works for files on the hard disk. However I have one assembly that is in memory and not on the disk. When I try to reference it, I get a FileNotFoundException which I expect since it is trying to add a path that doesn't exist.

So how do I pass in an actual Assembly object to CompilerParameters.ReferencedAssemblies?

I have seen a few posts online from 2006 and before that say it is simply not possible. I am hoping with .net 3.5 and .net 4.0 the support for this sort of thing has been added, but I am unsure.

FYI, I am using .NET 4.0


Also, right now I am creating a temporary file from the byte[] in program space, then loading that file into an assembly. I know the compiler does this in the background, but it also cleans up after itself I believe. It would be great if I could do:

CompilerParameters.ReferencedAssemblies.Add(Assembly a)
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Nick
  • 739
  • 11
  • 22
  • Didn't realize it was a contest, or that I even was "supposed" to mark questions as answered. – Nick Apr 15 '11 at 04:20

1 Answers1

1

So you have in-memory assembly that you want to add as reference?

I'm not sure that such approach is supported by CSharpCodeProvider.

abatishchev
  • 98,240
  • 88
  • 296
  • 433