BadImageFormatException when deploying on windows server 2012 r2 - c#

I am deploying my Asp.net application on Windows Server 2012 R2(x64). I get a runtime BadImageFormatException while using 64-bit dll. When I run it with IIS Express or application published on local machine IIS everything works well (Application pools -> solution name -> Enable 32-bit applications set to False, All projects in solution are also set for Platform target x64). Deploy is going through Team City & Octopus Deploy.
What the solution could be?
UPD
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at libxl.XmlBook.xlCreateXMLBookC() at xxx.Controllers.xxx.xxxController.LibxlTest() in C:\TeamCity\buildAgent\work\aeb63fe0b246a1f3\xxx\xxx\Controllers\xxx\xxx\xxxController.cs:line 597
There is no such path C:\TeamCity\buildAgent\ on server whrere the Octopus Tentacle is.

Finally, it works with x86 (from bin folder) version while the solution was build for x64. Probably, it is a peculiarity of libxl. Thus, I'm developing with x64 and after deploy my post-deploy script changes it for x86 version.

OK, it looks like you or one of your references has a dependency on libXL.
Your exception result (0x8007000B) is definitely a 32-bit can't load on 64-bit issue.
libXL is C++ project, in the download zip there's a bin64 folder with a copy of libxl.dll that will work in 64-bit mode.
If you have a libXL licensed copy better to use the 64-bit dll from that.
Note that C:\TeamCity\buildAgent\ comes from the machine your project was built on, the line numbers etc get saved into your pdb files.

Related

c#.net 32 bit application Not working on 64 bit OS

I am new to .NET application.
I have developed the application on 32 bit OS with Visual Studio 2008.
The application required the Microsoft.Interop services and for PDF services to open PDF files and MS Office files.
It also required SQL Express for database operations.
The application works fine on 32bit OS.
Then I created the setup for 64 bit OS, I added a new Setup project with wizard in Visual
Studio 2010 and select the Primary output and Localized resources.
But it does not included the Resources folder to the Application folder.
I set the target machine 64x and build the project, also before building give the prerequisites to the project which is Windows Installer 3.1, and .net framework 4.0, I have used the .net framwork 3.5 in the application.
Then I ran the setup, which executed successfully.
But when I tried to run the application it gave the message "Application has stoped working. Finding for the solution from the web.." and it closed.
Then I saw that there was no resources folder so I just copied the resources folder to the application where it was installed. Then the application worked fine.
So I created the setup again but this time I also provided the Resources folder to the application folder. Built the Setup and tried to run the application but the same message is prompted to me as it was giving before "Application has stopped working...", so I looked for the resource folder and all the required files which were there.
Creating a separate 64-bit version makes no sense in your case.
You have dependencies to 32-bit components; as a consequence, all1 your assemblies must be compiled to the x86 target platform and be installed using a 32-bit MSI.
If you get an "Application has stopped working..." error, this indicates that an exception occurred that has not been handled by your process. You can get the stack trace e.g. from the event log.
1 In fact, at the least the entry assembly must have an x86 target platform, and all other assemblies must have either an x86 or AnyCPU target platform.
Check you have changed the platform target to x64 or AnyCPU in your project -> Build Properties
hey friends thanks for answering my question. Finally doing a lot of things I found that it was converting the sql database to 2008 while creating the setup. And I was setting the sql express 2005 on the client machine. Then I changed the sql server 2005 to sql express 2008 and run the setup. Then I found that at the first time the exe required all the rights to convert so I tried the setup Run as Administrator and bingo the setup works for 2 different pc..
The only thing is required that at first time I need to run the application as Administrator.
Thanks for help I

BadImageFormatException on SQLite load on certain computer

I've created a very simple console app in .NET 4.0 that will run as a scheduled task. It looks for local files that are unmodified for a certain amount of time and then parses the file, inserts a record into a MySQL database, and copies the file to the network. I'm using a local SQLite database to track which files have already been processed, but unfortunately I'm running into a problem on one system at the first SQLite operation:
System.BadImageFormatException: Could not load file or assembly 'System.Data.SQLite.dll' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1) File name: 'System.Data.SQLite.dll'
at FileDatabase.CreateDatabaseAndTable()
at Program.Main(String[] args)
This exception is thrown on one system (Windows 7 x64 Home Premium with .NET 4.0 full), but is not thrown on two other systems (dev system + one other, both Windows 7 x64 Professional with .NET 4.0 full).
From browsing other questions, I see that this can happen when the program is run in 64-bit mode since the SQLite DLL is the 32-bit version. The first thing I checked is that the active platform is x86 in the Visual Studio Configuration Manager. I also used IL DASM to verify that the output exe is 32-bit (.corflags 0x00000003 // ILONLY 32BITREQUIRED). I would prefer to keep the 32-bit SQLite DLL and target platform as x86 so that I do not have to make different versions of the application for 32- and 64-bit computers.
I've also read that this exception can occur because of a corrupted DLL file, but since it works on some computers, I think this is not the case.
Other things I've tried on the problem system that didn't help:
Searching the GAC and Windows directory for errant SQLite DLLs, but found none.
Turning off AVG anti-virus.
Running the exe directly instead of the published ClickOnce application.
Uninstalling and reinstalling the ClickOnce application.
Any suggestions would be appreciated - thanks!
Installing the full setup package from system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki seems to have solved the problem - it must have been some dependency that was not present (possibly in Windows 7 Professional but not Home?). While this solution isn't perfect for a big deployment, I really just needed it on this one computer. Thanks for RoadBump for getting me on the right path.

Could not load file or assembly after deploy

I am developing app, which uses PDFLibNet.dll, everythings works fine on my pc, but when I deploy application and try to use it in another pc, creating PDFWrapper class (from PFDLibNet.dll) throw me an exception:
Could not load file or assembly "PDFLibNet.dll" or one of its dependencies.The specified module could not be found.
The same scenario on Win7 and XP
PDFLibNet.dll is stored in the same directory as binary .exe file of my app.
Any suggestion how to fix it?
I am using .Net4.0, Win7
Thanks!
It can be 2 possible reasons:
1. Check if dll was build for x86 or x64 or AnyCPU if you target machine x64 build your dll x64
2. It can be because of MS C++ redistrubute updates! uninstall them and try to start app again. Or you can either install the redistributable on the target machine.

C# application with access database won't work on 64 bit windows 7

I made C# application for my friend which has connection to access database (mdb file). I have developed application on my computer with win7 x86 installed. My friend had XP and it worked perfectly, but now he installed win7 x64 and application doesn't work. In fact, application starts and behave regular, but cannot connect to database... Database too can be opened with access, but my application cannot connect to it.
What can be a problem? How to make my application works on both operating systems?
regards,
Vajda
Ask your friend to download and install the following file:
Microsoft Access Database Engine 2010 Redistributable
and make sure he picks the 64-bit version there (AccessDatabaseEngine_x64.exe).
By default there is no 64-bit ODBC/OLEDB driver for Access installed, but the 2010 version should work for 2007 databases as well.
You could probably also configure your program to be built for the x86 target. That would run the program as a 32-bit program, even on 64-bit OS.
Most likely, the .Net CLR is trying to fire the app up in 64bit mode by default on his new win7 box and this might be causing some issues with the referenced assemblies.
The first thing I would try is to change the Platform target of the application (go to Project properties in Visual Studio for the application) to x86 (from Any CPU) to force the application to run in 32bit mode.
If this works, you will have narrowed down your problem.
Then, after building the project, look in the bin folder to see which assemblies are being copied to the output folder. If you see any System.Data... or any other .Net assemblies that are already contained in the GAC, you'll want to delete these and then try to fire it up. This will force the application to use GAC assemblies written for 64bit use.

Can a Windows Server 2003 32-bit machine application work for a Windows Server 2008 64-bit machine?

I am using a Windows Server 2003 32-bit machine. Using that machine I have created a COM component and consumed it in another application and have an EXE file.
Now I copy that EXE to another machine installed with Windows Server 2008, 64-bit.
And when I try to run that EXE it shows something like "Debug Error: This application needs runtime and terminates in an unusual way".
Is the bitness (32-bit vs 64-bit) compatibilty the reason for this? What could I need to run this on a Windows Server 2008 machine?
When you compile your app, you need to make sure that you compile it for 32 bit. By default, Visual Studio compiles for "Any". This leads to some parts of your app being 32 bit and using 64 bit DLLs.
The .NET framework built into Server 2008 is v3.0. Does your application require .NET v3.5? If so, you'll need to install the .NET 3.5 Redistributable package in Server 2008.
http://download.microsoft.com/download/6/0/f/60fc5854-3cb8-4892-b6db-bd4f42510f28/dotnetfx35.exe
It should works, thanks to WOW64.
You compiled as debug or release version?
And can it find all the references that are you using?
What development environment are you using? It sounds like your projects are configured to use the C++ runtime DLL for a version that is not installed on the target box.
There should be a VC_Redist.exe somewhere in your development environment that you can copy and execute on the target box to install the necessary runtime assemblies.
Or, go to every project, EXE and DLLs, and ensure that the "Runtime Library" setting under the Project Properties->C/C++->Code Generation page is set to one of the non DLL options (/MTd or /MT). This will bypass the need to install a separate runtime on the target PC, but will make your EXEs and DLLs a bit larger.

Categories

Resources