简体   繁体   中英

C# Compiler Parameters - metadata could not be found

While trying to compile some code out of .txt files (at run time), I have code which references Assemblies for the code that is being compiled.

It has been working fine for months, but I've recently had to add System.Speech.dll as one of the referenced assemblies, and now I am getting an error when it tries to compile the code in any of the text files.

Here's the error:

metadata file 'System.Speech.dll' could not be found

System.Speech.dll is in the references of the project as well, so if that could be the issue, it isn't. Also, all the other referenced dll's are completely fine, no errors for them at all.

Here's the section of code: (If you need more, please comment)

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

How can i remove this error? Thanks!

I was able to reproduce your error and solve it by doing the following change:

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

You need to change it to your location of course.

based on the comments, I would add the dll to the GAC. The gacutil.exe that ships with .NET can be used to add a assembly to the GAC.

To add a shared assembly, from the command line enter:

gacutil.exe /i mySpeechAssembly.dll

You could also use the full path to the assembly,

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

but I would advise against that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM