Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when debug c# code in 64 bit environment

Tags:

asp.net

64-bit

It seems the default running environment of Visual Studio is 32 bit. And I need to run one of my application in 64 bit mode. I did the change in project property like 'Platform Target' to 64 bit. But now am not able to run my application. I got an error like "Could not load file or assembly 'MyProject' or one of its dependencies. An attempt was made to load a program with an incorrect format."

Then I tried with a new blank WebApplication. Still in there also showing the same error. I remove all the reference dll files and added the dependencies from this path "C:\Windows\Microsoft.NET\Framework64". But unfortunately Still am getting same error.

I changed the Application Pool property of my IIS (Enable 32-Bit Application = True). Then tried to run in Local IIS Web Server but that too didn't worked.

Am using Windows 7, 64 bit OS and Visual Studio 2010. And when using the following c# code to find the running environment

using (RegistryKey registryKey = 
    Registry.LocalMachine.OpenSubKey(@"SOFTWARE\R-core\R"))
{
    var envPath = Environment.GetEnvironmentVariable("PATH");
string rBinPath = (string)registryKey.GetValue("InstallPath");
string rVersion = (string)registryKey.GetValue("Current Version");
rBinPath = System.Environment.Is64BitProcess 
        ? rBinPath + "\\bin\\x64" :rBinPath + "\\bin\\i386";
    Environment.SetEnvironmentVariable(
        "PATH",
    envPath + Path.PathSeparator + rBinPath);
}

The value of System.Environment.Is64BitProcess is always false I didn't want to follow the 64 bit path, if the running environment is 32 bit. So how to force VS to run in 64 bit mode?

Here I shared the error response page I got. Please help me to solve this issue Thank you.

Error Response Page

like image 333
Rameez Avatar asked Nov 11 '22 05:11

Rameez


1 Answers

Here's step by step a procedure which is ok from my VS2013, on a 64Bits OS

  • Create a blank app : New project type WebApplication > WebForm (or else) > no authentication

  • Target x64 : for the Debug mode from drop down list

    • Choose configuration manager
    • Choose platform new and select x64 as target platform
  • From the properties of your project, in the web tab

    • Choose Local IIS instead of IIS Express
    • Create Virtual Directory => The virtual directory was successfully created
  • Launch the app in debug mode from visual studio

like image 114
NicoD Avatar answered Nov 14 '22 22:11

NicoD