Repository navigation
Closed
Description
Here's the error I'm getting when I try to debug a task:
System.BadImageFormatException: Could not load file or assembly 'Microsoft.NET.Build.Tasks, Version=6.0.5.2708, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'Microsoft.NET.Build.Tasks, Version=6.0.5.2708, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at TaskRunner.Executor.Execute(Task task) in Z:\Projects\MSBuildStructuredLog\src\TaskRunner\Executor.cs:line 25
at TaskRunner.Program.Run(String binlog, Int32 index, String taskName) in Z:\Projects\MSBuildStructuredLog\src\TaskRunner\Program.cs:line 119
at TaskRunner.Program.Main(String[] args) in Z:\Projects\MSBuildStructuredLog\src\TaskRunner\Program.cs:line 63
Press any key to continue...
This error happens with both the latest version (2.1.561) and a freshly compiled version from the main branch (commit ddea3ae).
The project that I'm trying to debug is built for .NET 6.
I'm currently trying to figure out why this is happening…
Metadata
Metadata
Assignees
Labels
No labels
Activity
0xced commentedon Nov 19, 2021
So, the TaskRunner is a .NET Framework 4.7.2 exe with Prefer32Bit=true and it tries to load
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\tools\net6.0\Microsoft.NET.Build.Tasks.dllwithAssembly.LoadFrom(assemblyFilePath)and this is where theSystem.BadImageFormatExceptionoccurs.Next step is trying to multi-target the TaskRunner as
net472+net6.0and see what happens.0xced commentedon Nov 19, 2021
That's it, the .NET 6 TaskRunner executable works fine when loading
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\tools\net6.0\Microsoft.NET.Build.Tasks.dll. 😃Now I guess the challenge of multi-targeting the TaskRunner is how to determine which version should be launched to debug an MSBuild task!
KirillOsenkov commentedon Nov 20, 2021
Yup, see related #403
Thanks for investigating this!
Improve launching the TaskRunner