64 bit web application giving error - asp.net

I am getting following exception at runtime when I changed platform from AnyCpu to x64 of a web application. I am running it locally on windows 7 x-64
[BadImageFormatException: Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format.]

As well as checking whether you have any 32-bit components you should also check whether the ApplicationPool that's running your app is set to run as 32-bit. From IIS Manager > Application Pools > Your App Pool > Advanced Settings > Enable 32-Bit Applications. This should be set to False if you want to run in 64-bit mode or True if you want to run in 32-bit mode.

Sounds like you have a component/DLL that is 32-bit, while you are trying to force the Web Application to run solely as a 64-bit application.
You may also consider looking at:
Read

If you leave it as anycpu and it's compiled on a 64 bit system, it should compile and run on 32 and 64 bit. Don't try specifying an architecture when compiling unless you want it to be only 32bit specifically.
Ensure you have the 64bit framework installed.

Related

Attempt to load Oracle client libraries threw BadImageFormatException IIS System.Data.OracleClient

The Story: My website runs in System.Data.OraceClient(I cannot change the dll due to various technical reasons). Now, I have an third party DLL integrated to my website which is 32 bit. When I run from Visual studio everything runs perfectly, but when I publish it to IIS, it throws the above error.
Now Solutions are:
Enable 32 bit in IIS Application pool
When 32bit is enabled the Third party DLL will start to work and System.Data.Oracle client fails with BadImageFormat exception
Disable 32 bit in IIS Application pool.
When 32 bit is disabled System.Data.OracleClient will start to work and the third party DLL will fail with the below error.
Retrieving the COM class factory for component with CLSID {xxxxx}
failed due to the following error: xxxxxx Class not registered
-- This class is registered. That is why it works when 32 bit is enabled.
Now, I am in a situation only one dll will work at a time. Is there a workaround to make my System.Data.OracleClient run when 32Bit is enabled in Application pool without trying to migrate my entire application to Oracle Data Access?
I am thinking the only way to achieve this is to build your web application as 32 bit and that way let it use a 32 bit client. Then everything is 32 bit.
Make sure that your Web Application is built for x86. Do not build as AnyCpu as that will default to the target platform's x64.
System.Data.OracleClient is deprecated for ages and should not be used anymore. It is available only for x86 (32 bit), when Microsoft stopped developing of System.Data.OracleClient 64-bit Windows was not that common yet.
Better use the ODP.NET provider from Oracle, it is available for x86 and x64.
Check also this instruction: BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed

Configuring 32-Bit ASP.NET Application on a 64-Bit IIS Server

I’m trying to install a 32-bit ASP.NET application onto a 64-bit IIS server running on Windows Server 2008. This is a clean installation of the operating system with no other applications installed.
As a prerequisite for our installation, we run the 32-bit version of aspnet_regiis –i
It fails with the following message:
The error indicates that IIS is not installed on the machine. Please install IIS before using this tool.
Additionally:
IIS is definitely installed.
The 64 bit version of aspnet_regiis runs cleanly without warnings.
“Enable 32 bit applications” is set to True in the DefaultAppPool’s Advanced Settings.
The IIS Metabase and IIS 6 configuration compatibility” component is installed.
We have a test VM where this error occurs as well as test VM where both the 32 bit and 64 bit versions of aspnet_regiis run without errors. We've had no luck distinguishing the differences between the two test VMs.
We have struggled with this issue for several days to no avail. Any suggestions would be greatly appreciated!
Is it necessary to run aspnet_regiis? 32 bit asp.net should already be installed and running on iis7, all you should need to do is set the app pool to “Enable 32 bit applications” and set you web app to use that app pool. You do not say what happens when you install/setup your web app, do you get any errors when you try to access it in a browser?
Problem solved! Apparently the issue stems from Windows Server 2008 (R1). Applying the SP2 update to the operating system cures the problem. Later iterations of the OS don't seem to exhibit this behavior.

"The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine"...DNN

I'm trying to get a new DotNetNuke site up and running on our 64-bit server, and I'm encountering the following error message:
"The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine"
I know from experience that you run into this when you target a 64-bit assembly on a 64-bit machine (there is no 64 bit OLE-DB provider currently). In that case, I simply target the x86 in Visual Studio and everything works fine.
But in this case, the site uses dynamic compilation, so there's no simple place to specify that I need to target x86. Any thoughts?
TIA.
You could change your app pool that you're running that site under to run as a 32 bit application. In the IIS7 manager, its under "Advanced Settings" of your app pool, and then set "Enable 32-bit Applications" to true.
You could also do this with AppCmd from a console with the following:
appcmd apppool set /apppool.name:MyNukeSite /enable32BitAppOnWin64:true
In IIS6 - you could try something like this (2 lines here, run aspnet_regiis when finished changing the metabase value)...
cscript %SystemDrive%\inetpub\AdminScripts\adsutil.vbs set w3svc/AppPools/Enable32bitAppOnWin64 1
aspnet_regiis.exe -i
See the following for more info:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5d306956-b2a2-4708-9bb9-72a395d474bb.mspx?mfr=true
http://blogs.msdn.com/irfanahm/archive/2008/12/15/how-to-use-a-32-bit-dll-in-asp-net-page-which-is-hosted-on-64-bit-iis.aspx
http://support.microsoft.com/kb/895976
HI, Now the Microsoft has released the 2010 Office System Driver Beta: Data Connectivity Components which is supported both in 32 bit as well as 64 bit OS. So using this driver instead of the traditional Microsoft.Jet.OLEDB.4.0 driver will give us a 64 bit application running on a 64 bit server (that is what we really need).
Though this is in beta, it worked fine for me.
You can download this driver from 2010 Office System Driver Beta: Data Connectivity Components
Thnks
You shouldn't try to target your application to 32-bit in which case you are losing the advantages of using 64-bit system. As aaa has pointed out, you can use the latest Access Database Engine 2010 to address this issue. Please refer to my blog post for complete solution.
Hope it helps.

Running a Data Synapse Win32 DLL Grid Node on a Windows 64 Machine?

We are developing a Data Synapse calc node process in C# that requires functionality in a Win32 DLL. We have no problems building this.
The question is it has to run on a Windows 64 bit system, with Data Synapse 5.1 Grid APIs for Windows 64. While Windows 64 will run most processes transparently using WOW we don't know that Data Synapse's 64 bit will in some way stop this from working?
Anyone done this?
8 Jun 2009: Update.
when we try to run a win32 service on the win64 grid we run into problems because on Win64 the grid code intrastructure runs as 64 bit Java. This java calls our service using a win64 JINI call to our service which is implemented as a DLL. Unfortunately as a Win32 DLL.
Do you want your C# code to run as a .NET service? .NET Services run in-process and as far as I know, there is no way of mixing 32bit and 64bit code within a single process.
I see two solutions
1) Run 32bit DataSynapse engines OR
2) Run the C# code in a surrogate 32bit process. Use some form of IPC to communicate between some stub code running in the engine process and the surrogate process.
I believe this infrastructure has already been built by DataSynapse for C/C++ code and is called IsolateService. To use IsolateService a simple C->.NET bridge would need to be developed on the remote end or a .NET executable wrapper developed to host the .NET dll and handle COMs.
Nathan
Maybe you can install and run a win32 engine at the win64 machine, in that case everything is in WOW.
If you try to install a win32 engine on a win64 machine, make sure that your installed manager is ALSO USING a 32 bits JDK Java (look for the environment variable JAVA_HOME).
So, in order to have a 32-bit running on a 64-bit machine, you must have a 32-bit Java JDK, and the DataSynapse manager must have been installed pointing to the 32-bit Java machine (when installing the manager, the JAVA_HOME variable should be pointing to the 32-bit version).

Compile ASP.NET to 64 BIT

My development machine is Win XP Pro 32 bit and production machine is Windows Server 2008 (64 Bit) with IIS 7. On my development machine I want to compile ASP.NET (Using aspnet compiler) to 64 bit byte code.
Can anyone please tell me how to do that? Please do not suggest any way to run 32 bit application on 64 bit environment.
I want 64 bit application to be compiled on 32 bit machine so that when it runs it will take full advantage of 64 bit O/S without any emulation.
Leave the target platform at AnyCpu and .NET will automatically run natively on 64bit when executed on a 64Bit operating system
Clarification:
(this started out as a comment but I thought it might be interesting for the question as well)
Actually you never compile to a special architecture. You always compile to IL.
That's something like Java Bytecode. And that bytecode is the same for 32 bit and 64 bit.
The Virtual Machine (.NET Framework) on the machine the code gets executed then compiles the IL to actual machine code while running (through the Just In Time compilation). So, no matter where you compile, you'll always end up in IL that's bit-ignorant.
The setting in .NET is only an instruction in IL that tells the JIT (Just in Time compiler) to specifically use 32bit/64 bit. By flipping that one bit in your assembly you could still execute it in AnyCpu or x64 without recompilation.
This setting is only used and needed in case you call out to native code that isn't bit-ignorant (when interacting with COM components or doing p/invoke calls)
There's an option in Visual Studio 2013 now to direct IIS Express (which is usually used for debug) to run in 64 bit mode.
It's at Tools -> Options -> Projects and Solutions -> Web Projects -> Use the 64 bit version of IIS Express…
.net apps will re-target themselves for the target machine environment assuming that you didn't specifically choose to compile in 32-bit mode. This can be found under the project build options.

Resources