<p>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:</p>

<p>Metadata file 'System.Data.Linq.dll' could not be found</p>

<p>My code looks like:</p>

<pre><code>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");
</code></pre>

<p>Any ideas?           </p>

[{'answer_id': 60781, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 3, 'selected': True, 'text': '<p>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:</p>\n\n<pre><code>compilerParams.ReferencedAssemblies.Add(typeof(DataContext).Assembly.Location);\n</code></pre>\n'}, {'answer_id': 61306, 'author': 'Omer van Kloeten', 'author_id': 4979, 'author_profile': 'https://Stackoverflow.com/users/4979', 'pm_score': 0, 'selected': False, 'text': '<p>This may be a silly answer, but are you sure the code is running on a machine with .NET Framework 3.5?</p>\n'}]
['https://Stackoverflow.com/questions/60768', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5189/']