简体   繁体   中英

Unable to call .NET 4.6.1 project from DotNetCore when published to IIS

I currently have a DotNetCore REST API (targeting v2.1) that references a DotNetStandard project (targeting v2.0). The .NET Standard project has a reference to a .NET Full Framework project (targeting v4.6.1) which makes a call to a Sybase IQ database.

This all works perfectly when I am running my application in VS2017 using IIS Express, however once I publish the application and try to call the Api endpoint that references the .NET 4.6.1 application, I get the following error:

System.IO.FileNotFoundException: Could not load file or assembly >'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, >?>PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

The strange thing is that none of my projects or referenced Dlls are referencing System.Drawing.Common (or anything in the System.Drawing namespace). All the other functionality works as expected.

I have tried manually adding the System.Drawing.Common.dll using Nuget (the latest version is 4.5.1), but this doesn't resolve the problem. After adding the Nuget package, I tried adding an assembly binding redirect to the web.config in the published folder:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Drawing.Common" culture="neutral" 
            publicKeyToken="cc7b13ffcd2ddd51" />
            <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.6.26919.2" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

But the error still persists.

Does anyone have any ideas on what might be causing this?

Lex Li's answer was the correct one. I changed the target framework for the Api application to net471 and it now works as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM