I am trying to invoke the ffprobe.exe
file from the resources in Visual Studio. I find this answer on SO and tried to apply it to ffprobe. But I cannot load the bytes to assembly. But my code throws an System.BadImageFormatException: Bad IL Format
.
I googled the error message and found that it normally indicates that the binary is corrupt. I made sure that the loaded bytes are identical to the bytes of the ffprobe.exe
file from my resources, as this answer suggested. I wrote the bytes to a file and then compared it with the original file using the comp
command.
When calling the ffprobe.exe
file through the command line, it works perfectly. So I am sure it is not corrupt.
Here is what I tried:
object ob = Properties.Resources.ffprobe;
var ffprobeBytes = (byte[])ob; // ffprobeBytes is identical to ffprobe.exe in resources
var ffprobeAssembly = Assembly.Load(ffprobeBytes); // this line throws the Exception
var ffprobeEntry = ffprobeAssembly.EntryPoint;
var ffProbeObject = ffprobeAssembly.CreateInstance(ffprobeEntry.Name);
string[] parameters = { filePath, "=show_streams", "-print_format xml", "-loglevel fatal" };
var result = ffprobeEntry.Invoke(ffProbeObject, parameters)
The BuildAction
of the resource file is Embedded Resource
and Copy to output directory
is set to Copy always
.
Does anyone have an idea what could be the reason for this Exception?