Omnisharp-vscode: ProjectReference results in "type or namespace name 'System' could not be found" when Multi-Trageting

Created on 6 Mar 2018  路  24Comments  路  Source: OmniSharp/omnisharp-vscode

Environment data

dotnet --info output:

.NET Command Line Tools (2.1.4)

Product Information:
 Version:            2.1.4
 Commit SHA-1 hash:  5e8add2190

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.4/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

VS Code version:
1.20.1

C# Extension version:
1.14.0

Steps to reproduce

1- Create a mstest project
2- Open the folder in VS Code; verify there are no errors; Close the Folder
3- use DOTNET ADD to add a ProjectReference outside of root directory to the mstest project. The Reference Project must have use TargetFrameworks (multi-Target) not TargetFramework.
4- Open the folder in VS Code;

Expected behavior

No Problems/Error given that "dotnet build" works.

Actual behavior

Problem Panel displays lots of errors

Needs More Info Resolved-Fixed

Most helpful comment

Sorry how do we get this version in vscode? I'm on windows and see 1.17.1 for the c# extension. It appears to have omnisharp 1.31+, but it still can't pick up using System and tons of errors.

Here is my OmniSharp output

Starting OmniSharp server at 1/8/2019, 2:58:03 PM
    Target: c:\Users\user\Source\project_root\project_name.sln

OmniSharp server started.
    Path: C:\Users\user\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\OmniSharp.exe
    PID: 11172

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Visual Studio Professional 2017 15.6.27428.2002 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
            2: StandAlone 15.0 - "C:\Users\user\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Visual Studio Professional 2017 15.6.27428.2002 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'c:\Users\user\Source\project_root'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
        Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in 'c:\Users\user\Source\project_root\project_name.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'c:\Users\user\Source\project_root\project_name\project_name.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'c:\Users\user\Source\project_root'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: c:\Users\user\Source\project_root\project_name\project_name.csproj
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location 'c:\Users\user\Source\project_root' on host 21164.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file 'c:\Users\user\Source\project_root\project_name\project_name.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project 'c:\Users\user\Source\project_root\project_name\project_name.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: project_name

All 24 comments

@CalArabshahi What targets is your multitargeting project targeting?

I can confirm this issue with a multitargeted netstandard2.0 + net47 project reference. Changing projects in the solution to <TargetFramework>netstandard2.0</TargetFramework> got rid of the thousands of "System not found" errors.

dotnet --info
.NET Command Line Tools (2.1.103)

Product Information:
 Version:            2.1.103
 Commit SHA-1 hash:  60218cecb5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16299
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.103\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.6
  Build    : 74b1c703813c8910df5b96f304b0f2b78cdf194d

VS Code 1.21.1
Extension ver. 1.14.0

I suspect this is due to https://github.com/OmniSharp/omnisharp-vscode/issues/1750, which is ultimatey caused by https://github.com/OmniSharp/omnisharp-roslyn/issues/955. I believe you can address this by installing a recent Mono MDK from http://www.mono-project.com/download/stable.

We just tried to introduce <TargetFrameworks> and ran into this issue. Everything builds and runs just fine, but I have the issue described above: hundreds of errors, cannot locate System, etc. I am about to attempt installing Mono as a workaround, but I'm concerned about using VS Code in Linux.

I essentially have the same issue here. Hundreds of errors in VSCode, The type or namespace name 'Microsoft' could not be found, etc. Using VSCode for OSX here.

<TargetFramework>netcoreapp2.0</TargetFramework> in our solution.

@jpwiddy: Is your project a multi-targeting project? If not, it might be worth filing a new issue.

It's a single target project (just net core 2.0), referencing other projects that are multi-target. Really odd, it all started a few months ago out of the blue.

OK -- this might be the same thing in that case. If you're on OSX, installing the latest Mono MDK as mentioned earlier might fix it for you.

Yea I'm leaning on that this is the same error.

Just ran that installer, no change. Restarted the Omni VSCode extension, to no avail. Also tried uninstalling the extension and going from scratch, nadda.

If there's any more info I can add about my setup, please let me know.

Could you provide your full OmniSharp Log? You can retrieve this in VS Code by selection View->Output from the menu and then selecting "OmniSharp Log" from the dropdown at the top-right corner of the Output pane.

Starting OmniSharp server at 2018-5-10 08:47:35
    Target: /Users/jpwiddy/Development/Project/WebClient/WebClient.sln

OmniSharp server started wth Mono
    Path: /Users/jpwiddy/.vscode/extensions/ms-vscode.csharp-1.14.0/.omnisharp/omnisharp/OmniSharp.exe
    PID: 2094

锘縖info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 10.12.6 (x64)
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Mono 15.0 - "/Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin"
            2: StandAlone 15.0 - "/Users/jpwiddy/.vscode/extensions/ms-vscode.csharp-1.14.0/.omnisharp/omnisharp/msbuild/15.0/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 15.0 - "/Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin"
            CscToolPath = /Users/jpwiddy/.vscode/extensions/ms-vscode.csharp-1.14.0/.omnisharp/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/jpwiddy/Development/Project/WebClient'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Initializing in /Users/jpwiddy/Development/Project/WebClient
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Auto package restore: False
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Update workspace context
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Resolving projects references
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/Users/jpwiddy/Development/Project/WebClient/WebClient.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/jpwiddy/Development/Project/WebClient/WebClient.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/jpwiddy/Development/Project/WebClient/WebClient.csproj
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/jpwiddy/Development/Project/WebClient'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.Stdio.Host
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.Stdio.Host
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/jpwiddy/Development/Project/WebClient' on host 2008.
[warn]: OmniSharp.MSBuild.ProjectLoader
        Package 'MediaTypeMap 2.1.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
/Users/jpwiddy/Development/Project/WebClient/WebClient.csproj

[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/jpwiddy/Development/Project/WebClient/WebClient.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: WebClient
[info]: OmniSharp.MSBuild.ProjectManager
        Found referenced project outside root directory: /Users/jpwiddy/Development/Project/WebService.DataTransformation/WebService.DataTransformation.csproj

That's what I suspected would be the problem. The OmniSharp server does not yet support multi-targeted projects very well. What target frameworks does your WebClient projects have listed?

Ah gotcha.

<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
        <NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion>
    </PropertyGroup>
    <PropertyGroup>
        <TargetFramework>netcoreapp2.0</TargetFramework>
        <DebugType>portable</DebugType>
        <PreserveCompilationContext>true</PreserveCompilationContext>
        <AssemblyName>WebClient</AssemblyName>
        <OutputType>Exe</OutputType>
        <PackageId>WebClient</PackageId>
        <RuntimeIdentifiers>osx.10.11-x64;win10-x64;ubuntu.14.04-x64</RuntimeIdentifiers>
        <RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
        <TypeScriptToolsVersion>latest</TypeScriptToolsVersion>
        <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    </PropertyGroup>
    ...

and

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
        <NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion>
        <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
    </PropertyGroup>
    <PropertyGroup>
        <AssemblyName>WebService.DataTransformation</AssemblyName>
        <PackageId>WebService.DataTransformation</PackageId>
        <RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
        <NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
        <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
        <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
        <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    </PropertyGroup>
    ...

Hmmm... I was hoping that there would be a way to simply order your target frameworks to get things to work, but it doesn't look that way from the projects above. Like I mentioned, OmniSharp really doesn't support multi-targeted csproj projects well. In fact, if it encounters a <TargetFrameworks> property when no <TargetFramework> is defined, it just picks the first one.

Got it. I guess it has to default to something.

So I'm guessing this is something that needs to be addressed then in the (hopefully near) future?

Hello,

If nothing else, an error message perhaps in the log to indicate this situation? It is a hard one to troubleshoot otherwise.

Just curious, is there a way to manually ignore/disable some targets or hardcode a config somehow to target a specific target? That'd get me by for now.

No, there's no way to do that. OmniSharp really only calls the Compile and CoreCompile targets, which depend on a lot of other targets. I suspect that disabling some would mean that things just don't work.

I've made a few fixes to OmniSharp in this area recently. In particular, we identified a problem where it would fail to handle multi-targeted projects that were referenced outside of the current solution or folder that OmniSharp was launched with. Could you try using that version and see if it helps with this particular issue? You can use it by setting "omnisharp.path" to "latest" in the VS Code settings.

Actually just added that setting and restarted VS Code. If you're referring to

OmniSharp Version = 1.30.1-beta.63...

...then the results are much better. My Startup.cs file isn't littered with errors anymore!

Excellent! To others on this thread, does this address the problem?

Using latest version of omnisharp fixed this issue for me as well.

Great! I'm going to go ahead and resolved this in that case. It seems likely that this was fixed by https://github.com/OmniSharp/omnisharp-roslyn/pull/1195.

Sorry how do we get this version in vscode? I'm on windows and see 1.17.1 for the c# extension. It appears to have omnisharp 1.31+, but it still can't pick up using System and tons of errors.

Here is my OmniSharp output

Starting OmniSharp server at 1/8/2019, 2:58:03 PM
    Target: c:\Users\user\Source\project_root\project_name.sln

OmniSharp server started.
    Path: C:\Users\user\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\OmniSharp.exe
    PID: 11172

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Visual Studio Professional 2017 15.6.27428.2002 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
            2: StandAlone 15.0 - "C:\Users\user\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Visual Studio Professional 2017 15.6.27428.2002 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'c:\Users\user\Source\project_root'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
        Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in 'c:\Users\user\Source\project_root\project_name.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'c:\Users\user\Source\project_root\project_name\project_name.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'c:\Users\user\Source\project_root'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: c:\Users\user\Source\project_root\project_name\project_name.csproj
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location 'c:\Users\user\Source\project_root' on host 21164.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file 'c:\Users\user\Source\project_root\project_name\project_name.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project 'c:\Users\user\Source\project_root\project_name\project_name.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: project_name

In in a similar situation: I'm on macOS and using 1.17.1 for the C# extension and cannot load multitargeting libraries. (Those targeting _only_ netstandard2.0 are fine, if I enable multitargeting for netstandard2.0;net461 then omnisharp will show errors similar to 鈽濓笍 .)

@DustinCampbell - Is this not expected to work? User error? Would you prefer we open a new issue? (Thanks!)

Was this page helpful?
0 / 5 - 0 ratings