System.BadImageFormatException: Reference assemblies should not be loaded for execution

-1

I have added the reference file "System.Speech" from

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

It is required for proper execution of my program.

Here is my program:

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: '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)'

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

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.

Any solutions?

c#
.net
visual-studio
asked on Stack Overflow Apr 21, 2020 by jarol • edited Apr 21, 2020 by Denzil Soans

2 Answers

-1

It turns out I had the wrong Console App Visual Studio solution selected. I needed to, instead of selecting the Console App (.NET CORE), select the Console App (.NET Framework). The application now runs as anticipated.

Thanks to Denzil for further formatting my question.

answered on Stack Overflow Apr 21, 2020 by jarol
-1

BadImageFormatException: Could not load file or assembly 'System.Runtime.Extensions' or one of its dependencies. Reference assemblies should not be loaded for execution...

Fix: Delete the bin folder and rebuild the project.

answered on Stack Overflow May 9, 2020 by Murat Yıldız

User contributions licensed under CC BY-SA 3.0