Peter
Peter

Reputation: 3603

Unable to load System.Data.Linq.dll for CodeDom

I am trying to dynamicaly compile code using CodeDom. I can load other assemblies, but I cannot load System.Data.Linq.dll. I get an error:

Metadata file 'System.Data.Linq.dll' could not be found

My code looks like:

CompilerParameters compilerParams = new CompilerParameters();
compilerParams.CompilerOptions = "/target:library /optimize";
compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false;
compilerParams.ReferencedAssemblies.Add("mscorlib.dll");
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.Data.Linq.dll");

Any ideas?

Upvotes: 1

Views: 2454

Answers (2)

Omer van Kloeten
Omer van Kloeten

Reputation: 11980

This may be a silly answer, but are you sure the code is running on a machine with .NET Framework 3.5?

Upvotes: 0

Curt Hagenlocher
Curt Hagenlocher

Reputation: 20916

That may be because this assembly is stored in a different location than mscorlib is. It should work if you provide a full path to the assembly. The most convenient way to get the full path is to let the .NET loader do the work for you. I would try something like this:

compilerParams.ReferencedAssemblies.Add(typeof(DataContext).Assembly.Location);

Upvotes: 3

Related Questions