无法为CodeDom加载System.Data.Linq.dll
时间:2020-03-05 18:52:47 来源:igfitidea点击:
我正在尝试使用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");
有任何想法吗?
解决方案
回答
这可能是因为该程序集存储在与mscorlib不同的位置。如果我们提供装配的完整路径,它应该可以工作。获得完整路径的最方便方法是让.NET加载程序为我们完成工作。我会尝试这样的事情:
compilerParams.ReferencedAssemblies.Add(typeof(DataContext).Assembly.Location);
回答
这可能是一个愚蠢的答案,但是我们确定代码在装有.NET Framework 3.5的计算机上运行吗?