.NET standard 2.0 project not able to load Dapper 1.50.5

4

I am just starting out with .NET standard. In a proof-of-concept project I'm trying to use Dapper as my ORM. In the .NET Standard 2.0 class library project, I added Dapper 1.50.5 Nuget package. However, the assembly isn't getting loaded at runtime. I get this error:

System.IO.FileNotFoundException   HResult=0x80070002
Message=Could not load file or assembly 'Dapper, Version=1.50.5.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified.

Complete contents of my .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Dapper" Version="1.50.5" />
    <PackageReference Include="Npgsql" Version="4.0.4" />
    <PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
    <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
    <PackageReference Include="System.Reflection.TypeExtensions" Version="4.5.1" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
    <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" />
  </ItemGroup>
</Project>

So, you see I've installed the dependencies and dependencies of the dependencies.

What else should I do?

dapper
.net-standard-2.0
asked on Stack Overflow Dec 10, 2018 by KSK

1 Answer

2

The .NETStandard assembly was added as a reference to my WPF project. I needed to make changes in the .csproj of the WPF project.

The solution mentioned in https://github.com/dotnet/sdk/issues/901 fixes it.

Steps:

  1. Edit your core .csproj file in notepad.
  2. Add the below two lines in each that you find in it.

    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    
  3. Clean and rebuild your solution.

Yes... I used Notepad.

answered on Stack Overflow Dec 11, 2018 by KSK

User contributions licensed under CC BY-SA 3.0