aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

msbuild: BadImageFormatException for System.Runtime.InteropServices.RuntimeInformation 4.0.1

Open nemenos opened this issue 10 years ago • 11 comments

Hi everybody,

I have a solution with an aspnet core (xproj) targeting full .net framework 4.6.1 on windows 10, referencing other csprojs, inside the same solution.

All projects use project.json for nuget (instead of package.config).

Everything worked as intended yesterday, compiling from visual studio, or from command line using msbuild. After updating my aspnet core 1.0.1 to 1.1, everything is working good compiling using visual studio, but when I build with msbuild, build succedes, but starting webserver using

dotnet run projectfolder

kestrel, more precisely microsoft.aspnetcore.hosting throws exception:

System.BadImageFormatException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0...

Is it a known bug? Is it ok to use msbuild also after 1.1 version?

Thank you in advance,

Andrea

nemenos avatar Nov 17 '16 13:11 nemenos

BadImageException indicates bitness issues - i.e. trying to load 64-bit native dll into a 32-bit process.

moozzyk avatar Nov 17 '16 17:11 moozzyk

I think it's something incompatible between full dotnet framework and dotnet core framework. I found that running dotnet restore from command link says: unable to resolve "AssemblyName" for '.NETFramework,Version=v4.6.2' (now it's v4.6.2, because I updated everything, hoping to make it work, but it didn't)

nemenos avatar Nov 17 '16 17:11 nemenos

I had to rollback to dotnet core 1.0.1. Lost 2 days of work :( I hope this gets back woking soon

nemenos avatar Nov 18 '16 15:11 nemenos

Can you provide a repro - a working and non-working app after the upgrade?

moozzyk avatar Nov 18 '16 20:11 moozzyk

I'll try, but I think I will not have time for a few days... I'll update this thread asap. thank you

nemenos avatar Nov 21 '16 09:11 nemenos

I had some time to work on it again, atm I can use aspnet core 1.1, but I can't compile the whole solution using msbuild (v14.0). What I can see is that generated app.config is a lot different if compared with the one generated when compiling using visual studio. When compiling using msbuild a lot more assembly redirection are genereted: for example, System.Runtime.InteropServices redirection is only present on msbuild builded config

Can anyone help explaining me how are they generated, in both cases, so can investigate further? Thanks

nemenos avatar Nov 28 '16 13:11 nemenos

/cc @vijayrkn

moozzyk avatar Nov 28 '16 18:11 moozzyk

@BillHiebert

vijayrkn avatar Nov 28 '16 22:11 vijayrkn

I have this exact issue when using msbuild to build sln file directly.

I'm using msbuild on sln file in combination with /p:DeployOnBuild=true;PublishProfile=xxx to publish multiple web projects from solution. Is this supported for xproj? It was working fine in 1.0.0 and 1.0.1.

I narrowed down my problem to project ordering inside sln file. I have tried to create minimal repro and uploaded to https://github.com/dolly22/BadImageExceptionRepro. When I execute msbuild.exe NotWorking.sln, WebApp bin\Debug\net461\win7-x64\ folder contains wrong System.Runtime.InteropServices.RuntimeInformation.dll (22 504 bytes) and WebApp project.fragment.lock.json looks like...

{
  "version": 2,
  "exports": {
    "ClassicLib/1.0.0": {
      "type": "project",
      "framework": ".NETFramework,Version=v4.6.1",
      "compile": {
        "bin/Debug/ClassicLib.dll": {}
      },
      "runtime": {
        "bin/Debug/ClassicLib.dll": {},
	...
        "c:/users/dolly/.nuget/packages/system.runtime.interopservices.runtimeinformation/4.3.0/ref/netstandard1.1/system.runtime.interopservices.runtimeinformation.dll": {},
	...
      },
      "contentFiles": {
        "bin/Debug/ClassicLib.pdb": {
          "buildAction": "None",
          "codeLanguage": "any",
          "copyToOutput": true
        }
      }
    }
  }
}

When i execute msbuild.exe Working.sln, correct System.Runtime.InteropServices.RuntimeInformation.dll (33 256 bytes) is used and WebApp project.fragment.lock.json looks like...

{
  "version": 2,
  "exports": {
    "ClassicLib/1.0.0": {
      "type": "project",
      "framework": ".NETFramework,Version=v4.6.1",
      "compile": {
        "bin/Debug/ClassicLib.dll": {}
      },
      "runtime": {
        "bin/Debug/ClassicLib.dll": {}
      },
      "contentFiles": {
        "bin/Debug/ClassicLib.pdb": {
          "buildAction": "None",
          "codeLanguage": "any",
          "copyToOutput": true
        }
      }
    }
  }
}

Are you able to reproduce?

dolly22 avatar Dec 08 '16 11:12 dolly22

I just tried to reproduce, but for me, in both cases, Working.sln and NotWorking.sln, instead, work! if it doesn't on your machine, maybe is it a cache issue? Or am I doing it wrong to reproduce? I just did dotnet restore on both projects and tried to build with msbuild, no options.

Update: anyway I could solve the problem, instead of using msbuild on the solution, using it directly on the project. msbuild ./folder/project.xproj

Any idea why?

nemenos avatar Dec 09 '16 15:12 nemenos

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

aspnet-hello avatar Dec 30 '17 23:12 aspnet-hello