Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity assemblies targeting .Net framework 4.7.1 fail to load on Mac, plugin v2.0.328 #6048

Closed
ChongQingNoodle opened this issue Aug 5, 2023 · 9 comments
Assignees
Milestone

Comments

@ChongQingNoodle
Copy link

ChongQingNoodle commented Aug 5, 2023

Issue Description

Hello developers, when I use vscode to open my Unity(2022.2.15f1c1) project on Mac(macOS 13.2.1 (22D68)), I find that the code cannot be completed intelligently, and the C# plug-in reports an error.

Environment data

dotnet --info output:

.NET SDK:
Version: 7.0.306
Commit: f500069cb7

Runtime Environment:
OS Name: Mac OS X
OS Version: 13.2
OS Platform: Darwin
RID: osx.13-arm64
Base Path: /usr/local/share/dotnet/sdk/7.0.306/

Host:
Version: 7.0.9
Architecture: arm64
Commit: 8e9a17b221

.NET SDKs installed:
7.0.203 [/usr/local/share/dotnet/sdk]
7.0.306 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

VS Code version:

Version: 1.81.0 (Universal)
Commit: 6445d93c81ebe42c4cbd7a60712e0b17d9463e97
Date: 2023-08-02T12:40:02.782Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.3.0

C# Extension version:

Name: C#
Id: ms-dotnettools.csharp
Description: Base language support for C#
Version: 2.0.328
Publisher: Microsoft

OmniSharp log

Dotnet path: /Users/jiaziyan/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.9/dotnet
Activating C# standalone...
info: LanguageServerHost[0]
      Starting server...
[Info  - 4:20:11 PM] [LanguageServerProjectSystem]Loaded MSBuild at /usr/local/share/dotnet/sdk/7.0.306
[Info  - 4:20:11 PM] [LanguageServerProjectSystem]Loading /Users/jiaziyan/Desktop/Unity/Legend of the brave/Legend of the brave.sln...
[Warn  - 4:20:11 PM] [LanguageServerProjectSystem]Failure while loading /Users/jiaziyan/Desktop/Unity/Legend of the brave/Assembly-CSharp.csproj: **The reference assemblies for .NETFramework,Version=v4.7.1 were not found**. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
[Info  - 4:20:11 PM] [LanguageServerProjectSystem]Completed (re)load of all projects in 00:00:00.3454604
[Error - 4:20:19 PM] [LanguageServerHost]System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.Extensions.ITypeSymbolExtensions.GenerateTypeSyntax(INamespaceOrTypeSymbol symbol, Boolean nameSyntax, Boolean allowVar) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.cs:line 48
   at Microsoft.CodeAnalysis.CSharp.Extensions.ITypeSymbolExtensions.GenerateTypeSyntax(INamespaceOrTypeSymbol symbol, Boolean allowVar) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.cs:line 33
   at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.TypeExpression(ITypeSymbol typeSymbol, RefKind refKind) in /_/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs:line 3449
   at Microsoft.CodeAnalysis.Editing.SyntaxGenerator.TypeExpression(ITypeSymbol typeSymbol) in /_/src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs:line 1930
   at Microsoft.CodeAnalysis.Editing.SyntaxGenerator.TypeExpression(ITypeSymbol typeSymbol, Boolean addImport) in /_/src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs:line 1941
   at Microsoft.CodeAnalysis.Shared.Extensions.SyntaxGeneratorExtensions.CreateNotImplementedException(SyntaxGenerator codeDefinitionFactory, Compilation compilation) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/SyntaxGeneratorExtensions.cs:line 36
   at Microsoft.CodeAnalysis.Shared.Extensions.SyntaxGeneratorExtensions.CreateThrowNotImplementedStatement(SyntaxGenerator codeDefinitionFactory, Compilation compilation) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/SyntaxGeneratorExtensions.cs:line 24
   at Microsoft.CodeAnalysis.Shared.Extensions.SyntaxGeneratorExtensions.OverrideMethodAsync(SyntaxGenerator codeFactory, IMethodSymbol overriddenMethod, DeclarationModifiers modifiers, INamedTypeSymbol newContainingType, Document newDocument, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs:line 516
   at Microsoft.CodeAnalysis.Shared.Extensions.SyntaxGeneratorExtensions.OverrideAsync(SyntaxGenerator generator, ISymbol symbol, INamedTypeSymbol containingType, Document document, DeclarationModifiers extraDeclarationModifiers, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs:line 477
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractMemberInsertingCompletionProvider.GenerateMemberAndUsingsAsync(Document document, CompletionItem completionItem, TextLine line, CodeAndImportGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/Completion/Providers/AbstractMemberInsertingCompletionProvider.cs:line 149
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractMemberInsertingCompletionProvider.DetermineNewDocumentAsync(Document document, CompletionItem completionItem, CleanCodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/Completion/Providers/AbstractMemberInsertingCompletionProvider.cs:line 91
   at Microsoft.CodeAnalysis.Completion.Providers.AbstractMemberInsertingCompletionProvider.GetChangeAsync(Document document, CompletionItem item, Nullable`1 commitKey, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/Completion/Providers/AbstractMemberInsertingCompletionProvider.cs:line 44
   at Microsoft.CodeAnalysis.Completion.CompletionService.GetChangeAsync(Document document, CompletionItem item, Nullable`1 commitCharacter, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/Completion/CompletionService.cs:line 227
   at Microsoft.CodeAnalysis.LanguageServer.Handler.Completion.AbstractLspCompletionResultCreationService.GenerateComplexTextEditAsync(Document document, CompletionService completionService, CompletionItem selectedItem, Boolean snippetsSupported, Boolean insertNewPositionPlaceholder, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Completion/AbstractLspCompletionResultCreationService.cs:line 428
   at Microsoft.CodeAnalysis.LanguageServer.Handler.Completion.DefaultLspCompletionResultCreationService.ResolveAsync(CompletionItem lspItem, CompletionItem roslynItem, TextDocumentIdentifier textDocumentIdentifier, Document document, CompletionCapabilityHelper capabilityHelper, CompletionService completionService, CompletionOptions completionOptions, SymbolDescriptionOptions symbolDescriptionOptions, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Completion/DefaultLspCompletionResultCreationService.cs:line 94
   at Microsoft.CodeAnalysis.LanguageServer.Handler.CompletionResolveHandler.HandleRequestAsync(CompletionItem completionItem, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionResolveHandler.cs:line 66
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)
[Error - 4:20:19 PM] Request completionItem/resolve failed.
  Message: Object reference not set to an instance of an object.
  Code: -32000 
[object Object]

Steps to reproduce

  1. Create a project in Unity(2022.2.15f1c1)
  2. In the Unity project settings, in the Player column, set the Scripting Backend to mono, and set the Api Compatibility Level to .NET Framework.image
  3. Create the first C# script and open it in VS Code.
  4. Build a public abstract class in the first C# script,like this:image
  5. Create a second C# script and let the second one inherit from the abstract class in the first C# script, like this:image
  6. In the second one, try to complete the code of the first one's function, click on the completionItem, like this:image
  7. Observe the plugin fails completion.

Expected behavior

Code could be complete.

Actual behavior

The C# extension doesn't work in the VS Code,I can't complete the function code from the parent class.

@Ron3
Copy link

Ron3 commented Aug 5, 2023

I also have the same problem, does anyone know how to solve it?

@Ron3
Copy link

Ron3 commented Aug 5, 2023

@ChongQingNoodle

I have solved it by adding export FrameworkPathOverride=YourMonoInstallPath to ~/.zprofile

in my pc
FrameworkPathOverride=/Library/Frameworks/Mono.framework/Versions/Current/bin

@ChongQingNoodle
Copy link
Author

I also have the same problem, does anyone know how to solve it?

@Ron3 install another C# version could resolve it. I install C#v1.26.0 , than everything has been right.

@arunchndr arunchndr added this to the August milestone Aug 7, 2023
@arunchndr
Copy link
Member

There is some missing legacy csproj support that is tracked by #5721. But starting with @genlu to see if there is another fix for completion that can be made now.

@dibarbet
Copy link
Member

dibarbet commented Aug 7, 2023

The completion missing is caused because we weren't able to load the project successfully.
If you're able to use devkit, I'd recommend using the unity extension - https://devblogs.microsoft.com/visualstudio/announcing-the-unity-extension-for-visual-studio-code/

If you're not able to use devkit, we will likely not be able to load the project until #5721 is completed.
To workaround the issue, you can set the dotnet.server.useOmnisharp flag to get back to the old behavior.

@Ron3
Copy link

Ron3 commented Aug 14, 2023

I also have the same problem, does anyone know how to solve it?

@Ron3 install another C# version could resolve it. I install C#v1.26.0 , than everything has been right.

Since the 2.0.320 version, this plugin has made a lot of changes. If you use the old version, when you type ".", After that, the prompt speed will be very slow on my m1, even 5 seconds, 10 seconds later Prompt, while the new version is very fast, and should be able to prompt related properties/functions at the millisecond level.


https://marketplace.visualstudio.com/items/ms-dotnettools.csharp/changelog

2.0.320
We are switching to the new Roslyn language server as the default. We recognize that this version doesn’t have full parity with the OmniSharp version. If you need one of these features before we can get to it, you can switch back to OmniSharp by following these instructions.

@genlu
Copy link
Member

genlu commented Aug 15, 2023

As @dibarbet mentioned, this is a project load issue, even though it manifests as a completion error. The error is caused by us not able to retrieve the symbol of NotImplementedException from the compilation.

@genlu
Copy link
Member

genlu commented Aug 15, 2023

@jasonmalinowski Any thoughts on making errors like this more actionable? I believe (unconfirmed) this particular issue is we are not able to resolve system symbols like NotImplementedException. Could we employ some heuristics to tell if the project and references are loaded correctly before we hitting this kind of errors?

@genlu
Copy link
Member

genlu commented Sep 9, 2023

Fixed by dotnet/roslyn#69795

@genlu genlu closed this as completed Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants