Kunjahamed P

Kunjahamed P

  • 1.7k
  • 374
  • 28.3k

.net Standard 2.0 class library produce error when adding re

Jan 17 2020 9:47 AM
Created a .net Standard 2.0 class library, and then used it in a console application created by targetting .netframework 4.6.1 and dot net core 2.1. when running web application the blow exception was thrown.
Could not load file or assembly 'ChoETL.JSON.Core, Version=1.1.0.5, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
I tested same library with project reference in .net core web application and there was no error. when try with published DLL it show error in both core and framework application
Dotnet standard class library project file is
```
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ChoETL.JSON.NETStandard" Version="1.1.0.5-beta3" />
<PackageReference Include="ChoETL.NETStandard" Version="1.1.0.5-beta3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project>
```
early when adding project reference is .netframework 4.6.1 it show same error, then adding following setting in property group (project file) it disappear
<DependsOnNETStandard>true</DependsOnNETStandard>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
and is there any proper way to publish dotnet standard libary to work both .netframework 4.6.1 and dot net core 2.1

Answers (6)