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.

IDE shows missing netstandard.dll while build succeeds

See original GitHub issue

I’m using the latest (public) version of VS with the latest .NET Core tooling. I’m consuming a .NET Standard 2.0 library from a .NET Framework 4.6.1 project. The project builds and runs just fine, but shows errors in the IDE:

Errors in IDEs

Repro steps

  1. Create a .NET Standard 2.0 class library
  2. Change the code of Class1 as follows:
    using System;
    
    public class Class1
    {
        public (string key, int value) GetData()
        {
            return ("Meaning of Life", 42);
        }
    }
    
  3. Create a .NET Framework 4.6.1 console app
  4. Add a reference to the class library you created earlier
  5. Change the code of Program as follows:
    using System;
    
    class Program
    {
        static void Main(string[] args)
        {
            var c = new Class1();
            var data = c.GetData();
            Console.WriteLine(data);
        }
    }
    

Expected Behavior

No squiggles and no items in the error list.

Actual Behavior

The error list shows the following errors:

  • CS0012: The type ValueTuple<,> is defined in an assembly that is not referenced. You must add a reference to assembly netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51.
  • CS1503: Argument 1: cannot convert from (string key, int value) to bool

However, the project compiles & runs fine.

Findings

From @davkean

It’s very likely the compiler isn’t being given the netstandard.dll via the design-time build. No idea how this gets added to a .NET Framework 4.6.1 project – but whomever adds that dll should investigate. They can get the results of a design-time build: https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md#getting-visual-studio-to-output-the-results-of-a-design-time-build.

From @nguerrera

Please file a bug on dotnet/sdk as that’s where the component that adds the netstandard ref to netframework projects now lives.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
dsplaistedcommented, Jul 12, 2017

I’ve figured out what the problem is here. The issue is that we detect whether any references depend on .NET Standard using a task that looks at the metadata of the assembly to see if it has a reference to netstandard.dll. However, in this scenario, the project has not been built yet, so there is no assembly on disk for the task to examine.

Building the solution and then closing and re-opening it makes the issue go away.

A similar issue existed with the System.Runtime facades, and was resolved by adding metadata for the target platform to the item returned by the GetTargetPath target, which was then consumed in the ImplicitlyExpandDesignTimeFacades target.

So I’d propose we fix this bug in a similar fashion:

  • For projects targeting .NET Standard 1.5 or higher, add DependsOnNETStandard metadata to the _ResolvedProjectReferencePaths item returned by GetTargetPath
  • In Microsoft.NET.Build.Extensions.NETFramework.targets, check for that metadata as an alternate way of determining whether the project depends on .NET Standard

@rainersigwald @AndyGerlicher Ideally we’d add the DependsOnNETStandard metadata in the .NET SDK. The way the metadata is handled changed recently in https://github.com/Microsoft/msbuild/pull/2197. Is there a safe way for the SDK to add a target which runs after GetTargetPathWithTargetPlatformMoniker but before GetTargetPath which could add additional metadata to the TargetPathWithTargetPlatformMoniker item?

0reactions
terrajobstcommented, Jul 24, 2017

No longer repros for me. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

.NET standard dll is NOT generated all of sudden. - ...
When I compile "Way.Standard.AppGeneral" project after changing source code by adding a blank, compile succeed, but it doesn't generate ...
Read more >
Why is this NuGet dependency missing when compiling . ...
The build log mentions that project A tries to resolve its System.Data.SqlClient dependency from the NET Standard project C (and some wellknown ...
Read more >
Why not able to load netstandard.dll when creating new ...
Hi @Thangachamy Maruthaiah , The netstandard.dll you are trying to load is a reference assembly that which cannot be loaded for runtime on...
Read more >
Template for .NET STandard class library creates ...
NET Core in the left pane 4) in the right pane select Class Library (.NET Standard) 5) Click OK to generate the project...
Read more >
Tests fail discovery, dotnet --version wrong after VS2017 ...
The setup action is Uninstall on the line item selected in Programs and Features. The success messages are bogus - the items remain...
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