1

我正在尝试使用 CodeDom 动态编译代码。我可以加载其他程序集,但无法加载 System.Data.Linq.dll。我收到一个错误:

找不到元数据文件“System.Data.Linq.dll”

我的代码如下所示:

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");

有任何想法吗?

4

2 回答 2

3

这可能是因为此程序集存储在与 mscorlib 不同的位置。如果您提供程序集的完整路径,它应该可以工作。获取完整路径最方便的方法是让 .NET 加载程序为您完成工作。我会尝试这样的事情:

compilerParams.ReferencedAssemblies.Add(typeof(DataContext).Assembly.Location);
于 2008-09-13T19:18:03.490 回答
0

这可能是一个愚蠢的答案,但您确定代码在使用 .NET Framework 3.5 的机器上运行吗?

于 2008-09-14T12:45:55.097 回答