msbuild: BadImageFormatException for System.Runtime.InteropServices.RuntimeInformation 4.0.1
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
BadImageException indicates bitness issues - i.e. trying to load 64-bit native dll into a 32-bit process.
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)
I had to rollback to dotnet core 1.0.1. Lost 2 days of work :( I hope this gets back woking soon
Can you provide a repro - a working and non-working app after the upgrade?
I'll try, but I think I will not have time for a few days... I'll update this thread asap. thank you
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
/cc @vijayrkn
@BillHiebert
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?
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?
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.