WPF application fails with "bad image format" - wpf

I have an application build on my x64 computer. It is now build for x86 but on windows XP machines (x86) it fails with the "bad image format". On all Vista and up OS, it runs perfectly on x64 platfomrms. I tracked the problem to my icon.
I removed the icon and now it runs fine, anyone got an idea of how on earth this could relate to anything?

This error is basically telling you that a dll being loaded does not match the bitage (32 or 64) of the process. You could be loading up an assembly using native 64bit code, or it could be a single dll that is set to x64. You can use the corflags utility from the Visual Studio Command prompt to check what the .NET assembly bitage is set to.

Related

Windows forms app (visual studio 2010) compatibility issues

My task is to make a simple application that connects to the internet (using Wininet) and downloads a text file. It then displays the data in a listBox widget. The requirement was to make a GUI based application, so I used Windows Forms in Visual Studio Express 2010.
The application runs fine on my PC, however I realized that it runs only on my PC. I installed .Net 4 and Visual Studio 2010 redistributables on another PC and it worked fine there. Now, the person for whom I'm making this wants maximum compatibility on windows PCs. I'm totally stuck here.. should I switch to an older version of VSE?
From what I could search, using /MT instead of /MD would cause the application to link statically, however my app also uses /CLR and these are incompatible.
Any ideas?
Note: I've previously made a similar app (downloading and displaying) with console output and it works perfectly fine everywhere.
Dependens on what is meant by "maximum compatibility on windows PCs". If you can bundle the required redistributables, your program should run (as you found on the second PC), as long as the windows on the PC is capable of executing the binaries (e.g. not a 32 bit PC trying to execute 64 bit binaries)
I have been in your situation.
I can give you my free .NET-application-runner (RunNetApp.exe) that automatically installs .NET Framework 4 before running your application for the first time. If the framework is already installed on target machine, it only runs your application.
I also suggest changing application's framework to ".NET Framework 4 Client Profile". It's setup is about 40MB (in comparison to 200MB of full ".NET framework 4").
Is it helpful?

System.BadImageFormatException with Sqlite

I am trying to use SQLite with my WPF application. I can get the reads and writes to work ok. The only problem I have is that my xaml is not displaying and I get the following error:
System.BadImageFormatException
Could not load file or assembly 'System.Data.SQLite, Version=1.0.80.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.
My questions:
-How do I know what version of SQLite that I am using? 32bit or 64bit?
-I tried changing the Platform target to x86 and x64 but neither help. How can I resolve this error?
Had same problem when used 64-bit precompiled binaries. Solution is use 32-bit ones instead (manually download them from SQLite site if needed).
A System.BadImageFormatException error often occurs when a 64-bit assembly is opened by a 32-bit application or Conversely. In this case, Visual Studio is a 32-bit application and the Design view is attempting to load a 64-bit assembly. Visual Studio assemblies are located in the project references tree.
Right click on Your Project and select properties item. In Build Tab, change platform target to Any CPU.

Compiling 32-bit application using Visual Studio on a 64-bit machine

I'm trying to compile a simple 32-bit Hello World application written in C using Visual Studio 2010 on a 64-bit machine on a Windows 7 fresh install. I also installed the "Windows SDK for Windows 7 and .NET Framework 4" after installing Visual Studio.
I built the application selecting "Win32" as platform. It works on Windows 7 but if I run the application on my 32-bit machine with Windows XP Professional (fresh install also this, without softwares and Service Packs) it seems not working getting this error:
"This application has failed to start because msvcr100.dll was not found"
If it can be useful Dependency Walker detects 2 errors (see the linked picture for details):
"Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module."
"Error: Modules with different CPU types were found."
http://img820.imageshack.us/img820/4725/errordp.png (PIcture)
How can I solve it? Thanks!
The machine on which it is run needs the runtime libraries. See this MSDN information.
Don't trust Dependency Walker on this... It clearly shows your exe is 32 bit. Your problem is with the VC redistributables, which are the CRT dlls - look for vcredist_x86.exe in your VS installation. You should run it before you run your app.
Another option is to statically link the CRT. See the /MT option. Will make your exe larger, but save the vcredist stuff.
The problem here is the C runtime used by the compiled program is missing on the Windows XP machine. Visual Studio 2010 will by default us the 10.0 (msvcr100.dll) runtime which is not available on XP by default. You need to manually deploy the C runtime on your machine in order for your program to run.
You may want to read the following MSDN article which discusses the issues around deploying C applications built with Visual Studio 2010
http://msdn.microsoft.com/en-us/library/zebw5zk9.aspx
There may be additional 32 / 64 issues at work but this appears to be the primary problem
The answers about the runtime library are correct. Another possible solution is to link to the static runtime libraries rather than to the DLL versions. This way you can build an executable that you can drop onto any machine without extra deployment hassles.
It's a trade-off, but, without knowing more about your situation, it might be worth considering.

some troubles with WPF and Windows XP

is .net framework 3 compatible with xp? i install visual studio 9.0 (.net 3.5) on win XP. when i compile a WPF project and try to run it, this error occurs:
cannot initialize application ...... at address 0x<some digits>
(antivirus protection is off)
after first fail of wpf, all other project types (windows application, console &...) after compiling don't run.
where is problem?
WPF and .NET 3.5sp1 are supported on XP. You can create WPF applications with run on Windows XP.
It sounds like you have some other issue on your XP system. If other project types (ie: console) are failing, this is most likely some other, more serious issue.
Edit:
The System Requirements for .NET 3.5sp1, including WPF, are listed here. Basically, you need to have XPsp2 or better if you're using 32bit Windows XP, but both 32bit and 64bit XP are supported fully.

Application done in Windows XP SP3 not working in Windows 7

I have done a WPF appliction using VS 2008 SP1 in Windows XP SP3. I copy the exe and dlls to my Windows 7 RC build 7100 machine. But the exe is not working. When I doubleclick on the exe, a message comes like 'Application stop working. windows is gathering the information'. Why this happends?
I am overriding the OnStartup function in App.xaml.cs to create single instance of application. and also I am using DllImports for kernel32.dll, powrprof.dll, advapi32.dll and user32.dll. I use a Date control from the WPFToolkit
Have you tried to run in Backwards Compatibility Mode, by Right clicking the exe and going to the Compatiblity tab and trying different settings?
Also, did you test in more than one Windows 7 machine, to actually confirm its due to the Operating System difference and not due to a possible Framework installation problem?
Given that you are importing kernel32.dll, powerprof.dll, advapi32.dll, and user32.dll, my first guess is that you are running into a DLL-Hell problem. There is no concurrent versioning of those DLL's like there is with .NET assemblies. Make sure that the signatures you are importing have not been broken in the version of Windows 7 you are using.

Resources