views:

128

answers:

2

I'm trying to dynamically compile source code using the CodeDom.Compiler stuff, which means I need to reference the basic assemblies manually. The source code that I am compiling must be able to access the basic list extension methods, for for instance, Max(), Min(), or Sum(), and probably lambda expressions as well.

When I compile the source, it says I'm missing the required assembly... currently I include System.dll, and System.Core.dll.

Which dll do I need to get the extension methods for generics?

+7  A: 

Have a look at this blog post. You have to specify the compiler version manually when calling the CSharpCodeProvider constructor that receives a dictionary. Like this:

var provider = new CSharpCodeProvider(new Dictionary<string, string>{
                                       {"CompilerVersion", "v3.5"} });
Martinho Fernandes
thanks, that was it.
tbischel
A: 

The simple way to get past these type of hassles, is to look through Assembly.GetReferencedAssemblies(), and add references to the compiler that way. Then you know as long as your compiler compiles in Visual Studio, any code using those features will compile with your compiler.

Ch00k
Not the issue at hand: he stated in the question that he already references `System.Core`, and is `using System.Linq`. Using non-extension method syntax works, so, it's the problem lies elsewhere (compiler version).
Martinho Fernandes
My apologies for not knowing the answer to the question.
Ch00k