0

My scenario is that, I tried to build a very simple Asp.net web application, actually I did nothing but creating a new project of web (form) application using VB in visual studio 2012. Then, I changed the configuration to build it on x64 platform, and it always failed. But, if I change back to x86 platform, everything is fine. However, I do need a webapplicaiton built on x64.

When building it, no errors, but these warnings,


Rebuild All started: Project: WebApplication_debug, Configuration: Debug x64 ------ vbc : warning BC40010: Possible problem detected while building assembly 'WebApplication_debug': Referenced assembly 'mscorlib.dll' targets a different processor vbc : warning BC40010: Possible problem detected while building assembly 'WebApplication_debug': Referenced assembly 'System.Data.dll' targets a different processor vbc : warning BC40010: Possible problem detected while building assembly 'WebApplication_debug': Referenced assembly 'System.EnterpriseServices.dll' targets a different processor vbc : warning BC40010: Possible problem detected while building assembly 'WebApplication_debug': Referenced assembly 'System.Web.dll' targets a different processor


Then, when I run it, I got,


Could not load file or assembly 'WebApplication_debug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'WebApplication_debug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[BadImageFormatException: Could not load file or assembly 'WebApplication_debug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0 System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127 System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142 System.Reflection.Assembly.Load(String assemblyString) +28 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'WebApplication_debug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178 System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +163 System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +53 System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +175 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +86 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +261 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +101 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +126 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +62 System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33 System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37 System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +307 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


I have tried whatever I can, like setup IIS appPool, etc. No work out.

John Saunders
  • 160,644
  • 26
  • 247
  • 397

2 Answers2

1

It sounds like you're trying to load it in a 32-bit webserver.

Change it to Any CPU so it will load on both architectures.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • SLaks, thank you so much for your input. Yes, I know when I set to "Any CPU", it will work. But, as I mentioned, I like to just use x64 platform, because later on I need to call some Matlab-related dll that is based on 64-bit system. Everything is going well on my 32-bit machine. But, something is going wrong when I move it to 64-bit system. So, I guess I have to get a pure x64 web application work, then I can go ahead to finish the left. For your information, after I change to "Any CPU", build is ok, no error, no warning. run is Ok too. But, when I call some Matlab dll, error shows like bebow – user3103383 Dec 16 '13 at 17:41
  • Line 12: Line 13: Dim out_msg(1) As MWArray Line 14: out_msg(0) = New MWCharArray("can you see me in here?") Line 15: Line 16: 'MsgBox(out_msg(0).ToString) Source File: C:\Users\dongy\Visual_Studio_Projects\WebApplication_debug\WebApplication_debug\call_matlab_net_dll.aspx.vb Line: 14 – user3103383 Dec 16 '13 at 17:43
  • [BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)] MathWorks.MATLAB.NET.Utility.MWMCR.mclmcrInitialize2(Int32 primaryMode) +0 MathWorks.MATLAB.NET.Utility.MWMCR..cctor() +827 [TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception.] MathWorks.MATLAB.NET.Arrays.MWArray..cctor() +249 [TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception.] MathWorks.MATLAB.NET.Arrays.MWArray..ctor() +0 ... – user3103383 Dec 16 '13 at 17:43
  • Then make sure your web server is a 64-bit process. http://stackoverflow.com/q/10202047/34397 http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3254745-allow-for-iis-express-64-bit-to-run-from-visual-st – SLaks Dec 16 '13 at 17:44
0

If you build it on a 32bit machine, it is likely that you just don't have the 64bit .Net framework installed.

In addition, the built-in Dev server is also 32bit, so you won't be able to run it there.

ulu
  • 5,872
  • 4
  • 42
  • 51