How to resolve FileLoadException in .netcore

0

I have an asp.net core app which targets net472. It uses the nuget package for Microsoft.SqlServer.Types which references version 14.

However, when I run the app in Visual Studio, or deployed to Azure, this exception is thrown which says that version 10 could not be loaded.

What I am trying to do is use the SqlHierarchyId type which is located in this lib.

System.IO.FileLoadException HResult=0x80131040 Message=Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

How do I resolve this?

asp.net-core
asp.net-core-2.1
asked on Stack Overflow Oct 7, 2018 by Greg Gum • edited Dec 2, 2018 by Greg Gum

1 Answer

0

The resolution of this was to add an app.config with this:

<?xml version="1.0" encoding="utf-8"?>

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

Note that after you add this, clean and rebuilt the project to ensure that it takes effect.

answered on Stack Overflow Dec 1, 2018 by Greg Gum • edited Dec 2, 2018 by Greg Gum

User contributions licensed under CC BY-SA 3.0