Omnisharp-vscode: The type 'Attribute' is defined in an assembly that is not referenced.

Created on 26 Jun 2020  路  4Comments  路  Source: OmniSharp/omnisharp-vscode

Issue Description

"The type 'Attribute' 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'. [testproj]"

Steps to Reproduce

dotnet new xunit -o testproj
code . 

There will be a file UnitTest1.cs:

using System;
using Xunit;

namespace testproj
{
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {

        }
    }
}

Expected Behavior

No errors.

Actual Behavior

The [Fact] is underlined with a red wavy line (error).
In the Problems console there's an error: "The type 'Attribute' 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'. [testproj]"

Worth to mention, dotnet run, dotnet build, dotnet build work just fine, and the test passes.

Logs

OmniSharp log

Post the output from Output-->OmniSharp log here

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.46.1
C# Extension: 1.22.1

Mono Information
OmniSharp using global mono :6.8.0

Dotnet Information
.NET Core SDK (reflecting any global.json):
Version: 3.1.301
Commit: 7feb845744

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

Host (useful for support):
Version: 3.1.5
Commit: 65cd789777

.NET Core SDKs installed:
1.0.0-preview2.1-003155 [/usr/local/share/dotnet/sdk]
1.0.0-preview2-003131 [/usr/local/share/dotnet/sdk]
1.0.0-preview2-003148 [/usr/local/share/dotnet/sdk]
1.0.3 [/usr/local/share/dotnet/sdk]
2.0.0 [/usr/local/share/dotnet/sdk]
2.1.4 [/usr/local/share/dotnet/sdk]
2.1.200 [/usr/local/share/dotnet/sdk]
2.1.301 [/usr/local/share/dotnet/sdk]
2.1.500 [/usr/local/share/dotnet/sdk]
3.1.301 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.0-preview1-001100-00 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download


Visual Studio Code Extensions

|Extension|Author|Version|
|---|---|---|
|azure-account|ms-vscode|0.8.11|
|csharp|ms-dotnettools|1.22.1|
|debugger-for-chrome|msjsdiag|4.12.8|
|EditorConfig|EditorConfig|0.15.1|
|gitlens|eamodio|10.2.2|
|hide-gitignored|npxms|1.1.0|
|ng-template|Angular|0.1000.0|
|python|ms-python|2020.6.90262|
|rainbow-csv|mechatroner|1.7.0|
|sass-indented|robinbentley|1.5.1|
|vscode-eslint|dbaeumer|2.1.5|
|vscode-npm-script|eg2|0.3.12|
|vscode-todo-plus|fabiospampinato|4.17.1|
|vscode-typescript-tslint-plugin|ms-vscode|1.2.3|;

Most helpful comment

@filipw "omnisharp.useGlobalMono": "never", solved the problem. Thank you for your help and for the great extension!

All 4 comments

can you please post the Omnisharp log?

@filipw thank you!

Starting OmniSharp server at 6/26/2020, 11:36:32 PM
    Target: /Users/roma/Developer/testproj

OmniSharp server started with Mono 6.8.0.
    Path: /Users/roma/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/OmniSharp.exe
    PID: 24784

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 10.15.5 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Mono 16.4 - "/usr/local/Cellar/mono/6.8.0.105/lib/mono/msbuild/Current/bin"
            2: StandAlone 16.4 - "/Users/roma/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 16.4 - "/usr/local/Cellar/mono/6.8.0.105/lib/mono/msbuild/Current/bin"
            CscToolExe = csc.exe
            CscToolPath = /Users/roma/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin/Roslyn
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/roma/Developer/testproj'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        No solution files found in '/Users/roma/Developer/testproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/roma/Developer/testproj/testproj.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/roma/Developer/testproj'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/roma/Developer/testproj/testproj.csproj
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/roma/Developer/testproj' on host 24764.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/roma/Developer/testproj/testproj.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/roma/Developer/testproj/testproj.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: testproj
[warn]: OmniSharp.MSBuild.PackageDependencyChecker
        testproj: Did not find 'Microsoft.NETCore.App' in lock file.

I believe the Cellar Mono you have is the problem. Can you instead install Mono from the official source https://www.mono-project.com/download/stable/ or try "omnisharp.useGlobalMono": false?

@filipw "omnisharp.useGlobalMono": "never", solved the problem. Thank you for your help and for the great extension!

Was this page helpful?
0 / 5 - 0 ratings