1

I am trying to create a .Net Standard 2.0 library (I am using visual studio 22) I encountered the following problem while running the project:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

This is my .csproj file:

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

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <OutputType>Exe</OutputType>   
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="RestSharp" Version="106.15.0" />
    <PackageReference Include="Serilog" Version="4.0.0" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
  </ItemGroup>

</Project>

There were a lot of problems with the packages, so I added the line:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

But it only solved some of the errors (I downgraded some of the packages to solve other errors) but I was left with the above error. I am new to .net and would really appreciate your help. (And if you ask why .net standrad then it's because I need to produce a package from my code that will fit several different versions (both core and framework)

4
  • It seems peculiar that you are creating an EXE that targets .NET Standard. As far as I'm aware, you usually target .NET Standard in library projects, i.e. that create a DLL, so that can then be consumed by EXEs and other DLLs that target various frameworks. Maybe that's the issue. Commented Jul 10 at 6:13
  • @jmcilhinney is right. For running a project you need to have <OutputType>Exe</OutputType> with <TargetFramework>net8.0</TargetFramework> Commented Jul 10 at 7:00
  • @jmcilhinney I removed the EntityFrameworkCore packages from my project, and now it runs. I run it as a console app now and I do have <OutputType>Exe</OutputType> However, I no longer have database access.
    – Ranel
    Commented Jul 10 at 7:11
  • If you have another idea, I would appreciate it. My program works well in .net8 but I need to make a package from it that will work for framework4.6.2 what can I do?
    – Ranel
    Commented Jul 10 at 7:20

0