question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running tasks compiled for netcore throws ReflectionTypeLoadException

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
matkochcommented, 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 net472 just fine. Thanks for your quick response! ❤️

0reactions
KirillOsenkovcommented, Oct 12, 2020

Quick repro steps to get the binlog:

  1. git clone https://github.com/matkoch/custom-msbuild-task
  2. edit kirill.bat to make sure this path exists: C:/Program Files/dotnet/sdk/3.1.401/MSBuild.dll and change to whatever you have installed
  3. run kirill.bat, it will produce C:\custom-msbuild-task\src\TestProject\msbuild.binlog
  4. open msbuild.binlog in the viewer, find $task CustomTask, right-click and Run or Debug

Expected: should work

Actual: ReflectionTypeLoadException because trying to load a task assembly targeting .NET Core on a .NET Framework process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReflectionTypeLoadException in ASP.NET Core MVC ...
An unhandled exception has occurred: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more ...
Read more >
System.Reflection.ReflectionTypeLoadException when ...
According to the exception in your logs, the analyzer your project is trying to load is relying on some type that is unavailable....
Read more >
ReflectionTypeLoadException when running dnx (aspnet5)
Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property at System.
Read more >
What is System.Private.CoreLib.dll and why is it giving me ...
When I run the build from visual studio I get an error message in the Development Console saying: Error could not find assembly...
Read more >
How to resolve “Could not load file or assembly … or one of its ...
Cached Assembly: Check the same assembly bound before then use it, if it failed then current request is failed immediately without any further...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found