Skip to main content
 首页 » 编程设计

C# 编译器参数之找不到元数据

2024年02月20日12wuhuacong

在尝试从 .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"); 

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

请您参考如下方法:

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

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

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