.Net 5 - using System.Web - Reference assemblies should not be loaded for execution. (0x80131058)

2

I'm porting a .Net 4.5 Framework app to .Net 5 (I want to publish a single executable with dotnet publish -r win-x64 -c Release -p:PublishSingleFile=true --self-contained true /p:IncludeNativeLibrariesInSingleFile=true).

I packaged dll into a NuGet package. This includes System.web.Services.dll (4.0.300319.18020, a .Net Framework 4.5 dll I think) along with it's dll.

Nuget package reference

This builds with a .csproj file of

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net5.0-windows</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <Folder Include="Properties\" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="ReportingServices2010" Version="1.0.4" />
        <PackageReference Include="SharpZipLib" Version="1.3.0" />
        <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    </ItemGroup>
</Project>

At run time, I get this:

System.BadImageFormatException: Could not load file or assembly 'System.Web.Services, 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)
File name: 'System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.

I've been searching for awhile, but I haven't found a way around this. I think that .Net 5 can reference this directly, especially with TargetFramework>net5.0-windows</TargetFramework>. Why can't it load it? Why is the error message Version=4.0.0.0? Where is it attempting to load the dll from (is the GAC still something in .net 5?)

.net
msbuild
.net-5
asked on Stack Overflow Nov 24, 2020 by AlignedDev

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0