c# project target platform of 64bit machine - c#

I have a c# project which is linked with c++ project. I am running my application in 64 bit machine now. How to configure the c# project to 64 bit? There is some compatibility issue I am facing in 64 bit machine now.
Previously I was running my application in 32 bit machine. It was working perfectly. In 64 bit machine the linking fails as part of my c++ code is giving the right output. when the c# linking code is hit the execution stops without throwing any errors.

You might have to set-up your project to target x86 or x64 specifically (depends on your C++ library).

Related

Why would a x86 compiled application work on 64 bit windows machine?

I installed windows 7 64 bit and then I installed visual studio 2015 then created C# application using windows forms and I compiled this application as x86 (as shown in screenshot) to creat the exe file . After that I installed the .exe file on another 64 bit windows 7 and the application worked fine!
My question is: why this x86 complied application would work on 64 bit machine. I read that if I compile application as x86 it would only work on x86 machines.
Can anyone explain why it worked on 64 bit machine? thank you
The reason is because your 64bit CPU is specically designed for this as well as the operating system you're using.
In short, the OS detect that you're trying to run a x86 application and put the CPU in x86 compatibility mode before executing your application.

Deployed 64bit c# application can't load unmanaged dll

I have a 64bit web application written in c# deployed to IIS on both windows server 2008 (IIS 7) and windows server 2012 (IIS 8).
Part of the application involves accessing an unmanaged c++ DLL from c# code. This call is failing when I deploy to IIS. I get the classic:
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
I have read many threads on the topic, including:
An attempt was made to load a program with an incorrect format ERROR
“An attempt was made to load a program with an incorrect format” even when the platforms are the same
But I don't think they apply as
I have a 64 bit application.
It's compiled as x64
It's deployed as x64
I have verified it is running under an x64 IIS appPool.
enable32bitapplications is set to false.
Both the c# dll importing and the unmanaged dll are compiled to 64bit.
I have deployed to IIS on the server machines in both Release and Debug mode - no difference.
There are 32 bit dlls in the application, but they are in completely separate projects which are not referenced by, nor reference, the project that is throwing the error.
For additional information, it runs fine on both my local machine in IIS express AND my local machine when deployed through IIS (windows 7), so there is a disconnect somewhere and I can't track it down.
Additional info:
The unmanaged DLL does have dependencies on:
Kernel32.dll
Advapi32.dll
Crypt32.dll
User32.dll
Version.dll
I realize these are 32bit I thought these were 32bit, but on a 64 bit machine these live in System32, so I'm not sure... but if so, how can I get it to compile as the unmanaged DLL itself is compiled to 64 bit.
Also, why would it work locally for me?
Also, I have (just for kicks and skittles) set Enable32BitApplications to True and I get the same error, as my project is a 64 bit project and references a 64bit unmanaged DLL, which can't run in a 32 bit process.
There was an additional dependency for the unmanaged DLL that was a c++ redistributable dll. The copy of that DLL on the machine was 32 bit, once I swapped out the version to be 64 bit, it loaded just fine.
Lesson learned, all dependencies of the DLL must be present and the correct Bitness.
You need to set Enable32bitApplications to true in IIS.

An attempt was made to load a program with an incorrect format ERROR

I am trying to create a webservice where the functions are performed by a 64 bit DLL. When I try to build this service i get the error "An attempt was made to load a program with an incorrect format."
But when I run a 32 bit DLL it works fine.
I am trying to run in a visual studio 2012 on .net 4 framework in C#
I have tried changing the app pool settings in IIS and changed build platform target to any cpu. Cannot identify where the problem is coming from. Please provide you assistance. Thank you
Right click on the application pool you are using and go to Advanced Settings. Under (General) there is a setting called Enable 32-Bit Applications. If you're running on a 64 bit OS and this is set to true then the app-pool will be a 32bit process, and therefore your 64bit DLL won't load. Set it to false to make your app-pool a 64bit process.
Also, check the dependencies of the DLL you're building as 64bit. It may be using a 32bit dll/assembly. If you've got any [DllImport] attributes in your code then look at the .dlls they refer to and ensure they're 64bit compatible.
If your web service references 64 bit dlls it must be compiled to x64
Try not to mix AnyCPU compilation with 32 or 64 bit DLL (DLL can be compiled as 32bit or 64bit or both) - behavior will depend on platform and in some environments it will work, in some not.

DLL Errors in 32 bits machine. Program made in C#

I did a program in C# which runs perfectly in my machine and in another one, of 64 bits, which have the .NET Framework.
When I try to run the program in a 32 bits machine It explodes and I get:
In this link (http://geekswithblogs.net/steveclements/archive/2008/04/30/error--eventtype-clr20r3.aspx) I found some solutions, but none worked for me. I already deleted the not used DLL, in particular those involving MySQL.
Do you have any suggestions?
Thank you.
This question requires more error details like exception information, VS version, What kind of exe (Winforms, WPF, etc), but you can start by answering the following questions:
- Is your exe built for anyCPU?
Is the same .net framework version installed on both 64-bit and 32-bit PC?
Are you having any code that uses 64-bit dll?
Are you having any code that uses 64-bit constructs? (checking pointer size)
What VS/.net framework/OS version does your developer PC has? The 32-bit PC?

C# Crash on x64

I have a DLL created in VS 2008 and written in C#.
The dll project builds with the "Any CPU" flag.
When it is deployed and run on a Dell/Intel Windows 7 x64 machine it starts up OK, but it crashes when it tries to start using cryptography -- TDESAlgorithm.CreateDecryptor();
This is part of the mscorlib.dll.
I've built the app as targeting x64, but it also crashes in the same place. It runs fine on 32 bit machines.
How can I get this to run successfully on x64?
I ran into similar problem with windows services created in .NET. It was throwing exception and the Windows log file indicated errors in mscorlib.dll and kernel32.dll (if I remember correctly). No external 32 bits dll or special codes was used, only plain .NET.
The solution I got is to compile as x86 and then run it (as 32 bits) application on the 64 bits machine. This could be a solution as long as you don't need 64bits to run your app.
The solution I got is to compile as x86 and then run it (as 32 bits)
application on the 64 bits machine. This could be a solution as long
as you don't need 64bits to run your app. - Gaël Mo
I'd just like to point out that compiling and running for x86 on a 64 bit machine is NOT an answer... Joe would like to know why its crashing in x64 mode... obviously running in x86 mode works on x64 machines. If you couldn't get your car to run with a certain after-market part, would you consider it a valid answer if I told you to simply run the car without the part in it? Obviously not... Think carefully about your answers before posting them ok?
Does it run on the x64 machine if you build it for x86? If so, they
something isn't 64-bit ready. – sgmoore
I agree... I'd like to add that if you do not have the source code (you probably don't) then you are out of luck I'm afraid... I found THIS article that explains more fully... Apart from that, you may need to look into a different DES decryption library... OpenSSL/SSH perhaps?

Categories