System.BadImageFormatException:不应加载参考程序集以执行

问题描述:

我从


Program Files(x86)\参考
中添加了参考文件 System.Speech程序集\Microsoft\Framework.NETFramework\v4.5.2\System.Speech.dll。

"Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\System.Speech.dll".

正确执行我的程序。

这是我的程序:

using System;
using System.Speech.Synthesis;

namespace ConditioningSchemas
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Initializing...");
            SpeechSynthesizer synth = new SpeechSynthesizer(); // Initialize a new instance of SpeechSynthesizer.
            synth.SetOutputToDefaultAudioDevice(); // Configure output to Default Device (soundcard)
            synth.Speak("Dominate");
            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    }
}

这是错误消息我已经收到:

This is the error message that I've been receiving:


System.BadImageFormatException:'无法加载文件或程序集
'System.Speech,Version = 4.0.0.0,文化=中性,
PublicKeyToken = 31bf3856ad364e35'。参考程序集不应加载
来执行。它们只能在仅反射的
加载程序上下文中加载。 (0x80131058)'

System.BadImageFormatException: 'Could not load file or assembly 'System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)'

内部异常:BadImageFormatException:无法加载引用
程序集以执行。

Inner Exception: BadImageFormatException: Cannot load a reference assembly for execution.

我在其他帖子中看到,我可以删除 obj和 bin文件夹,然后清理解决方案,然后该项目应该可以工作。我还尝试将整个解决方案迁移到解决方案,但该程序无法正确执行。

I saw in other posts that I can delete the "obj" and "bin" folders and then clean the solution and then the project should work. I also tried migrating the entire solution to a solution but the program will not execute properly.

任何解决方案?


BadImageFormatException:无法加载文件或程序集'System.Runtime.Extensions'或其依赖项之一。不应加载参考程序集以执行...

修复: 删除 bin 文件夹并重建项目。

Fix: Delete the bin folder and rebuild the project.