question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build fails targeting 4.5.2 if dotnet core SDK not installed

See original GitHub issue

Our builds are failing on build agents without dotnet core SDK installed after upgrading to 4.0.3 from 3.2.5 and targetting .NET 4.5.2.

Steps to reproduce

Upgrade from 3.2.5 to 4.0.3 using NuGet package manager (reproduced both on Visual Studio 2017 latest release and Jetbrains Rider latest release), targeting .NET 4.5.2

The issue

Build will fail if dotnet core is not installed on the building machine.

Error message:

error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

This is how nuget package manager modifies one of the .csproj files (see the reference to netstandard in HintPath):

    <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
      <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
      <HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
      <Private>True</Private>
    </Reference>

Further technical details

Npgsql version: 4.0.3 PostgreSQL version: not relevant as it’s not a runtime issue. Operating system: Windows Server 2012 (for build machines). Windows 10 and MacOs for dev machines where code changes are implemented.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hnfmrcommented, Oct 19, 2018

I am having the exact issue here within a F# project (dotnet build): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

I am in macOS, clean dotnet install with version 2.1.403, however, the following two workarounds work for me:

  1. Downgrade npgsql to 3.2.7
  2. Copy a version of System.Runtime.CompilerServices.Unsafe.dll (version 4.5.2) to the root directory of the project also works…

I got the idea of downgrading from this post: https://community.powerbi.com/t5/Desktop/a-problem-connecting-wiht-postgresql-database/td-p/431097

0reactions
rojicommented, Nov 18, 2018

@stefanoric, sorry for disappearing for so long, I was very occupied with non-Npgsql things.

I’ve checked, and the references to netstandard assemblies can be considered the expected behavior. The System.ValueTuple package, for example, contains assemblies for net461, net47, portable-net40+sl4+win8+wp8 and netstandard1.0 (among several others). Now, .NET Framework 4.5 supports .NET Standard 1.0, and it would appear that the nuget resolution rules favor that over portable-net40+sl4+win8+wp8. This doesn’t really have anything to do with Npgsql - it’s about .NET dependency resolution.

Now, you can probably manually change your csproj to depend on the portable-net40+sl4+win8+wp8 instead. However, at least in theory there shouldn’t be a problem to reference a netstandard10 library from a .NET Framework project - this is supposed to work just fine. But it’s true that .NET Standard 1.0 involves its complications, so this may be a valid workaround at least for now.

Note that if I do the same experiment from a .NET Framework 4.6.1 project, I get a reference to the net461 assembly of System.ValueTuple instead. System.Runtime.CompilerServices.Unsafe does reference netstandard20 but that’s supposed to be much less complicated than pre-2.0, so it should not give you any trouble whatsoever.

@hnfmr this may or may not also address your comment, there isn’t enough information to know. If you still have an Npgsql-related issue, please open a separate issue with a full code sample.

@dropyghost you’re issue doesn’t seem related at all - I checked and found that a reference toSystem.ValueTuple is indeed missing from the VSIX csproj. I opened #2230 to address that for 4.0.4.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Targeting pack for .NET 4.5.2 not installed
How I found that link. First, choose option 1, "Change the target to .NET Framework 4.5". Next, go to the project options of...
Read more >
NETSDK1045: The current .NET SDK does not support ...
This error occurs when the build tools can't find the version of the .NET SDK that's needed to build a project. This is...
Read more >
Troubleshoot .NET Framework targeting errors
This article provides resolutions for MSBuild errors that might occur because of reference issues.
Read more >
Building a project that target .NET Framework 4.5 in Visual ...
So, the fix is simple: just copy the files from that package to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4 ...
Read more >
Visual Studio 17.4.5 no older net core targeting
Description. I cannot see older net core sdk in projects template (below .net core 2.1). Configuration .Net core environment path order:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found