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.

Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context

See original GitHub issue

How to reproduce:

  1. Launch DLLExport.bat in the solution directory.
  2. Choose a .Net standard 2.1 project.
  3. choose platform x86.
  4. Click Apply.
  5. use [DllExport] attribute.
  6. build the project.
  7. this error message appears:

net.r_eg.DllExport.targets(76, 5): [MSB4062] The “RGiesecke.DllExport.MSBuild.DllExportAppDomainIsolatedTask” task could not be loaded from the assembly C:\Users\Administrator\Desktop\Workflow\Devices\packages\DllExport.1.7.0\tools\RGiesecke.DllExport.MSBuild.dll. Could not load file or assembly ‘Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058) Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

When jumping to source it goes to here:

<DllExportAppDomainIsolatedTask
          Platform="$(DllExportPlatform)"
          CpuType="$(DllExportCpuType)"
          DllExportAttributeFullName="$(DllExportAttributeFullName)"
          EmitDebugSymbols="$(DllExportEmitDebugSymbols)"
          LeaveIntermediateFiles="$(DllExportLeaveIntermediateFiles)"
          Timeout="$(DllExportTimeout)"
          KeyContainer="$(DllExportKeyContainer)"
          KeyFile="$(DllExportKeyFile)"
          ProjectDirectory="$(DllExportProjectDirectory)"
          InputFileName="$(DllExportInputFileName)"
          FrameworkPath="$(DllExportFrameworkPath)"
          VsDevCmd="$(DllExportVsDevCmd)"
          VcVarsAll="$(DllExportVcVarsAll)"
          LibToolPath="$(DllExportLibToolPath)"
          LibToolDllPath="$(DllExportLibToolDllPath)"
          TargetFrameworkVersion="$(DllExportTargetFrameworkVersion)"
          SdkPath="$(DllExportSdkPath)"
          SkipOnAnyCpu="$(DllExportSkipOnAnyCpu)"
          OrdinalsBase="$(DllExportOrdinalsBase)"
          GenExpLib="$(DllExportGenExpLib)"
          OurILAsmPath="$(DllExportOurILAsmPath)"
          MetaLib="$(DllExportMetaLibFullPath)"
          PeCheckRaw="$(DllExportPeCheck)"
          PatchesRaw="$(DllExportPatches)"
          SysObjRebase="$(DllExportSysObjRebase)"
         />

at file net.r_eg.DllExport.targets

-version: v1.7.0.60761+0a002a7

-build-info:

S_NUM: 1.7.0 S_REV: 60761 S_NUM_REV: 1.7.0.60761 S_REL: bSha1: 0a002a7 bName: master bRevc: 201 MetaCor: netstandard1.1 MetaLib: v2.0 Wizard: v4.0 Configuration: PublicRelease Platform: Any CPU cfgname: Release revDeltaBase: 2016/10/12 revDeltaMin: 1000 revDeltaMax: 65534

The full command to Manager: ./DLLExport.bat

Project type: .Net standard project

Environment ( VS, MSBuild, …): .Net core 3.1, IDE IS Rider 2019.3, not Visual Studio, MSBuild version is 16. log: DllExport.bat output hMSBuild.bat -debug -only-path output vswhere -requires Microsoft.Component.MSBuild -products * -latest output

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
abnud1commented, Apr 2, 2020

hmsbuild Devices.sln /t:Rebuild /m:4 /v:diag > build.log This command actually built project successfully !!!

I now know the problem, dotnet build command doesn’t work, specifically, the MSBuild that comes with dotnet core doesn’t work, what works is the MSBuild.exe that comes with visual studio.

I’m not sure if this issue is resolved though, dotnet build should work as it’s a legal way to build dotnet core projects.

0reactions
3Fcommented, Apr 2, 2020

You must use msbuild tools today instead of dotnet cli.

it’s a legal way to build dotnet core projects.

Same for msbuild tools! Even officially they recommends to use exactly this instead of dotnet build for some related problems with tasks etc. Officially DllExport today provides support only for msbuild tools, visual studio, and related. I’m not using mentioned IDE IS Rider but I’m sure you can configure build through this easily.

I close this issue. You can also open a new one for add support or discuss an alternative to dotnet build.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Could not load file or assembly Microsoft.Build.Utilities. ...
The system cannot find the file specified. I am using Visual Studio 2013 update 5. The target framework for my project is .NET...
Read more >
How to fix System.BadImageFormatException
Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)'.
Read more >
Couple of issues with solution with .NET Core project
FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its ...
Read more >
How to resolve “Could not load file or assembly … or one of its ...
fuslogvw.exe is assembly binding log viewer (installed with Visual studio), run it from developers command prompt with admin privileges. Go to debug (under...
Read more >
How to: Load Assemblies into the Reflection-Only Context
Code loaded into this context can only be examined; it cannot be executed. This means that objects cannot be created, because constructors cannot...
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