1

在尝试从 .txt 文件中编译一些代码(在运行时)时,我的代码引用了正在编译的代码的程序集。

几个月来它一直运行良好,但我最近不得不将 System.Speech.dll 添加为引用的程序集之一,现在当它尝试编译任何文本文件中的代码时出现错误。

这是错误:

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

System.Speech.dll 也在项目的引用中,所以如果这可能是问题,它不是。此外,所有其他引用的 dll 都完全正常,完全没有错误。

这是代码部分:(如果您需要更多,请评论)

        CompilerParameters options = new CompilerParameters();
        options.ReferencedAssemblies.Add("System.dll");
        options.ReferencedAssemblies.Add("System.Core.dll");
        options.ReferencedAssemblies.Add("System.Drawing.dll");
        options.ReferencedAssemblies.Add("System.Speech.dll");

我怎样才能消除这个错误?谢谢!

4

2 回答 2

3

我能够重现您的错误并通过执行以下更改来解决它:

CompilerParameters options = new CompilerParameters();
        options.ReferencedAssemblies.Add("System.dll");
        options.ReferencedAssemblies.Add("System.Core.dll");
        options.ReferencedAssemblies.Add("System.Drawing.dll");
        options.ReferencedAssemblies.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Speech.dll");

当然,您需要将其更改为您的位置。

于 2012-07-16T14:00:06.563 回答
1

根据评论,我会将 dll 添加到 GAC。.NET 附带的 gacutil.exe 可用于将程序集添加到 GAC。

要添加共享程序集,请从命令行输入:

gacutil.exe /i mySpeechAssembly.dll

您还可以使用程序集的完整路径,

options.ReferencedAssemblies.Add(@"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Speech.dll")

但我建议不要这样做。

于 2012-07-16T14:00:53.287 回答