I have an executable in a Class Library that is marked as an Embedded Resource in the Build Action field in the item properties. When writing the file to disk, no exceptions are raised, but attempting to run the executable produces this error:
"Unsupported 16-Bit Application
The program or feature "\??\path\to\exe" cannot start or run due to incompatibity with 64-bit versions of Windows. Please contact the software vendor to ask if a 64-bit Windows compatible version is available." (incompatibility being spelled wrong is intentional, it is spelled incorrectly on the error box)
Same error, different exe (from Google Images/MSDN):
I have verified that the item is not corrupted before it gets embedded in the DLL, and have tried many of the answers here and here to write the file to disk, and none of them have worked. They all produce the same error.
Code for writing the executable to disk:
public static void WriteEmbeddedToDisk(string embeddedFilename, System.Type assemblyType, string diskFilepath)
{
using (var input = Assembly.GetAssembly(assemblyType).GetManifestResourceStream(embeddedFilename))
using (var output = File.Create(diskFilepath))
{
input.CopyTo(output);
}
}
Code for running the executable:
public static bool RunExe(string path, string arguments)
{
try
{
var psi = new ProcessStartInfo(path, arguments);
psi.CreateNoWindow = true;
psi.UseShellExecute = true;
psi.RedirectStandardOutput = false;
var process = Process.Start(psi);
process.WaitForExit();
process.Close();
}
catch
{
return false;
}
return true;
}
Other information that may be important:
- The executable is in Class Library A
WriteEmbeddedToDisk()
andRunExe()
are in the same class in Class Library B- The same error has occured when writing a different executable to disk via the same process. That executable was also in Class Library A.