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 issueHow to reproduce:
- Launch DLLExport.bat in the solution directory.
- Choose a .Net standard 2.1 project.
- choose platform x86.
- Click Apply.
- use [DllExport] attribute.
- build the project.
- 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:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top GitHub Comments
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.You must use msbuild tools today instead of dotnet cli.
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
.