dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.1k stars 4.04k forks source link

Error when loading .NET Standard 2.0 DLL in C# Interactive #21604

Closed shaggygi closed 6 years ago

shaggygi commented 7 years ago

Version Used: VS 2017.3 RTM

Steps to Reproduce:

  1. Open VS 2017.3 and C# Interactive
  2. Reference a local .NET Standard 2.0 DLL using '#r'. e.g. C:\Test\Demo.DLL
  3. Try to instantiate a class within the DLL.

Expected Behavior: Should be able to use Interactive with the DLL.

Actual Behavior: Get the following error:

Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. + AsyncTaskMethodBuilder.Start(ref TStateMachine)

scegg commented 7 years ago

To access a dotnet standard dll, you need to reference netstandard library in main (host) application. So you need to pass this assembly to Roslyn while compiling your code.

shaggygi commented 7 years ago

I tried this with VS 15.4 RTM and appears to now work in C# Interactive. I can close out unless there is something else being investigated here.

cshaa commented 6 years ago

I'm using VS 2017 15.5.0 and experience the same issue. When I right-click on a “.NET Standard 2.0 library” project, the “Initialize C# Interactive with Project” doesn't appear and when I reference it with #r I get Could not load file or assembly....

alexzaytsev-newsroomly commented 6 years ago

Same here, i used VS 15.5.2.

cshaa commented 6 years ago

A walkaround is to double-build the project – once for production, targetting .NET Standard, and the other time for Interactive, targetting a specific .NET Framework. Then you can load the built dlls using the #r directive. But it's so annoying that most of the time it's not worth it and it's better to copy-paste the code right into the Interactive console 😕 Not a great victory for .NET Standard and fast prototyping.

tmat commented 6 years ago

When I right-click on a “.NET Standard 2.0 library” project, the “Initialize C# Interactive with Project” doesn't appear

The new project system doesn't support this command yet. It does not matter whether the library targets .NET Standard (<TargetFramework>netstandard20</TargetFramework>) or .NET Framework (<TargetFramework>net46</TargetFramework>).

when I reference it with #r I get Could not load file or assembly...

I do not have a problem referencing netstandard2.0 library "manually" in VS 2017 Update 6 Preview 6 like so:

image

Can anyone share a library (.dll) that demonstrates the problem?

shaggygi commented 6 years ago

This still appears to be working for me in 15.7.5, so I'm closing.

@m93a The "Initialize Interactive with Project" is being tracked here #26934.