Repository navigation
Closed
Description
When I simply run my task as part of MSBuild, it works as expected. AFAIR, I was able to run/debug it specifically StructuredLogViewer, but yesterday it failed on me.
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at TaskRunner.Executor.Execute(Task task) in C:\MSBuildStructuredLog\src\TaskRunner\Executor.cs:line 32
at TaskRunner.Program.Run(String binlog, Int32 index, String taskName) in C:\MSBuildStructuredLog\src\TaskRunner\Program.cs:line 114
at TaskRunner.Program.Main(String[] args) in C:\MSBuildStructuredLog\src\TaskRunner\Program.cs:line 61
One of the assemblies is System.Runtime:
=== Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/Users/matthias.koch/AppData/Local/MSBuildStructuredLogViewer/app-2.1.208/
LOG: Initial PrivatePath = NULL
Calling assembly : CustomTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\matthias.koch\AppData\Local\MSBuildStructuredLogViewer\app-2.1.208\TaskRunner.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Users/matthias.koch/AppData/Local/MSBuildStructuredLogViewer/app-2.1.208/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/matthias.koch/AppData/Local/MSBuildStructuredLogViewer/app-2.1.208/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/matthias.koch/AppData/Local/MSBuildStructuredLogViewer/app-2.1.208/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Users/matthias.koch/AppData/Local/MSBuildStructuredLogViewer/app-2.1.208/System.Runtime/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/code/custom-msbuild-task/src/CustomTasks/bin/Debug/netcoreapp2.1/publish/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/code/custom-msbuild-task/src/CustomTasks/bin/Debug/netcoreapp2.1/publish/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/code/custom-msbuild-task/src/CustomTasks/bin/Debug/netcoreapp2.1/publish/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/code/custom-msbuild-task/src/CustomTasks/bin/Debug/netcoreapp2.1/publish/System.Runtime/System.Runtime.EXE.
Anything else I can provide to give more insight?
Metadata
Metadata
Assignees
Labels
No labels
Activity
KirillOsenkov commentedon Oct 12, 2020
What's the Task name? What's the .dll file that the task is in? Can you share the .dll file with me? First dot last at my employer dot com.
KirillOsenkov commentedon Oct 12, 2020
OK, I understand what's going on. The task .dll is targeting .NET Core, whereas TaskRunner.exe is a net472 desktop app.
I'm going to have to write logic to detect whether the task assembly is targeting .NET Core, and start TaskRunner.exe via "dotnet TaskRunner.exe". I'm also going to need to generate
TaskRunner.runtimeconfig.jsonwith this contents next to TaskRunner.exe:Depending on which framework is installed on the machine.
KirillOsenkov commentedon Oct 12, 2020
As a temporary workaround, you can view the task Id in binlog viewer by choosing "Search in subtree" and seeing which ID it adds to the search box:
Then write this content to
C:\Users\kirillo\AppData\Local\MSBuildStructuredLogViewer\app-2.1.208\TaskRunner.runtimeconfig.json:Then run
where 616 is the unique ID of the task.
Unfortunately I'm not sure when I'll have time to implement the above logic so you don't have to do this manually. But it would consist of:
C:\Program Files\dotnet\dotnet.exeorC:\Program Files\dotnet\dotnet.exe)KirillOsenkov commentedon Oct 12, 2020
This is where the logic needs to be added:
MSBuildStructuredLog/src/StructuredLogViewer/Controls/BuildControl.xaml.cs
Line 464 in 61cd163
KirillOsenkov commentedon Oct 12, 2020
Quick repro steps to get the binlog:
C:/Program Files/dotnet/sdk/3.1.401/MSBuild.dlland change to whatever you have installed$task CustomTask, right-click and Run or DebugExpected: should work
Actual: ReflectionTypeLoadException because trying to load a task assembly targeting .NET Core on a .NET Framework process.
matkoch commentedon Oct 12, 2020
@KirillOsenkov arg! I actually thought about this but must have forgotten to update one of the references. Can confirm that it's working with
net472just fine. Thanks for your quick response! ❤️[-]Run/debug task throws ReflectionTypeLoadException[/-][+]Running tasks compiled for netcore throws ReflectionTypeLoadException[/+]Improve launching the TaskRunner