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

System.Reflection.ReflectionTypeLoadException when getting code actions #5105

Open
ArmaanMcleod opened this issue Mar 12, 2022 · 16 comments
Open

Comments

@ArmaanMcleod
Copy link

ArmaanMcleod commented Mar 12, 2022

Environment data

dotnet --info output:

.NET SDK (reflecting any global.json):
 Version:   5.0.406
 Commit:    3a48fd6fe5

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

Host (useful for support):
  Version: 5.0.15
  Commit:  3065735be7

.NET SDKs installed:
  3.1.417 [C:\Program Files\dotnet\sdk]
  5.0.212 [C:\Program Files\dotnet\sdk]
  5.0.406 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

VS Code version:

1.65.0
b5205cc8eb4fbaa726835538cd82372cc0222d43
x64

C# Extension version:

v1.24.1

OmniSharp log

[fail]: OmniSharp.Stdio.Host
        ************  Response (11.9941ms) ************ 
{
  "Request_seq": 1259,
  "Command": "/v2/getcodeactions",
  "Running": true,
  "Success": false,
  "Message": "\"System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.\\r\\n   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)\\r\\n   at System.Reflection.RuntimeAssembly.get_DefinedTypes()\\r\\n   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()\\r\\n   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\\r\\n   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\\r\\n   at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()\\r\\n   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\\r\\n   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\\r\\n   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.LoadFrom(Project project) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 93\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.GetAllCodeFixesForProject(ProjectId projectId) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 57\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.GetSortedCodeFixProviders(Document document) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 156\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.<AppendFixesAsync>d__13.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.<CollectCodeFixesActions>d__12.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 123\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.<GetAvailableCodeActions>d__9.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 80\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService.<Handle>d__1.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\GetCodeActionsService.cs:line 32\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.<GetFirstNotEmptyResponseFromHandlers>d__19.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.<HandleRequestForLanguage>d__20.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 230\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.<Process>d__16.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 131\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at OmniSharp.Stdio.Host.<HandleRequest>d__14.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Stdio\\\\Host.cs:line 218\"",
  "Body": null,
  "Seq": 53207,
  "Type": "response"
}

Steps to reproduce

Example Issue is here: https://github.com/Azure/PSRule.Rules.Azure/blob/main/src/PSRule.Rules.Azure/Data/Template/ExpressionHelpers.cs#L218

Where the refactor suggestion is 'if' statement can be simplified [PSRule.Rules.Azure].

If you try Ctrl + ., it says No code actions available.

Expected behavior

This stopped working recently. Ussually I can refactor with Ctrl + . just fine.

Actual behavior

No code actions available message popup.

@lonix1
Copy link

lonix1 commented Mar 13, 2022

I have this too!

If you try ctrl+. a few times does it eventually work? May be related to #5085 and #5091

There are a MANY problems with the newest version. vscode devs, please release a hotfix for #5089 so we don't have to wait a whole month for the next release. Rolling back is also no good as there were bugs there too, so were excited to upgrade to this release, but now there are new bugs!

@filipw
Copy link
Contributor

filipw commented Mar 14, 2022

According to the exception in your logs, the analyzer your project is trying to load is relying on some type that is unavailable. This is a relatively common problem on the minimal Mono that OmniSharp by default ships with.

Probably the best solution would be to switch to the .NET 6 build of OmniSharp by setting "omnisharp.useModernNet": true" - unless you are developing a Unity project, which would require you to install latest preview global Mono and set "omnisharp.useGlobalMono":"always".

@filipw filipw changed the title Fail to get code actions System.Reflection.ReflectionTypeLoadException when getting code actions Mar 14, 2022
@lonix1
Copy link

lonix1 commented Mar 15, 2022

@filipw I have the same problem, but my log is:

[fail]: OmniSharp.Stdio.Host
        ************  Response (120.3542ms) ************ 
{
  "Request_seq": 379,
  "Command": "/v2/getcodeactions",
  "Running": true,
  "Success": false,
  "Message": "\"System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\n\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, 

  // .......it goes on like this for many 100s of lines.....

  "Body": null,
  "Seq": 3917,
  "Type": "response"
}

I am using the dotnet6 build, NOT unity, with "omnisharp.useModernNet": true, "omnisharp.useGlobalMono": "never"".

@filipw
Copy link
Contributor

filipw commented Mar 15, 2022

This is not the same problem , only looks similar.

In your case the missing type is 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. This means your analyzers require Roslyn 4.1.0 but your OmniSharp does not have it, which tells me you are on old version of the extension.

OmniSharp was upgraded to Roslyn 4.1.0 OmniSharp/omnisharp-roslyn#2329 here, which shipped in extension 1.24.1. You need to upgrade to that.

@ArmaanMcleod
Copy link
Author

ArmaanMcleod commented Mar 30, 2022

@filipw Thanks for providing this. Unfortunately we can't really upgrade .NET 6 SDK just yet. Not really a big issue, I can just do code refactoring through VS for the time being.

Would be great if upgrades were more backwards compatible with older .NET versions, since this was working for me not to long ago.

Any chance this could get fixed in an upcoming release or is upgrading the only option?

@filipw
Copy link
Contributor

filipw commented Mar 30, 2022

The types needed at runtime are not dictated by OmniSharp but by our dependencies (primarily Roslyn) and any analyzer packages your project would use. The minimal Mono bundled by OmniSharp does not have the full .NET type surface available for size reasons and such missing type errors happen(ed) from time to time. You did not post the full log so I do not known which OmniSharp mode you are running, but judging by the exception I am guessing it is this minimal Mono.

Now that said, this minimal Mono mode (that was used by default so far) is currently deprecated, is no longer maintained and has already been removed in the latest beta version.

Going forward you have two options:

In either case, the full .NET type surface will be available.

@jonkelling
Copy link

jonkelling commented Apr 12, 2023

I just came across this, but the latest suggestion is not working for me. I installed Mono for Windows x64. useGlobalMono is no longer available. I set the monoPath to C:\Program Files\Mono. Works fine in macOS.

@jtsom
Copy link

jtsom commented Apr 24, 2023

I am also seeing this on a small .NET 7 project. Simple code fixes are not available (naming violations, etc.) Seeing the same System.Reflection.ReflectionTypeLoadExceptoin over and over.

{
  "Request_seq": 350,
  "Command": "/v2/getcodeactions",
  "Running": true,
  "Success": false,
  "Message": "\"System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.\\r\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\r\\nCould not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\r\\n   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.<>c.<LoadFrom>b__6_0(AnalyzerFileReference analyzerFileReference) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 64\\r\\n   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()\\r\\n   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\\r\\n   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\\r\\n   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)\\r\\n   at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)\\r\\n   at System.Linq.Enumerable.Concat2Iterator`1.ToArray()\\r\\n   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.LoadFrom(Project project) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 95\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects.GetAllCodeFixesForProject(ProjectId projectId) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\CachingCodeFixProviderForProjects.cs:line 57\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.GetSortedCodeFixProviders(Document document) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 170\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.AppendFixesAsync(Document document, TextSpan span, IEnumerable`1 diagnostics, List`1 codeActions) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 142\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.CollectCodeFixesActions(Document document, TextSpan span, List`1 codeActions) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 134\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2.GetAvailableCodeActions(ICodeActionRequest request) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\BaseCodeActionService.cs:line 86\\r\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService.Handle(GetCodeActionsRequest request) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Refactoring\\\\V2\\\\GetCodeActionsService.cs:line 34\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.GetFirstNotEmptyResponseFromHandlers(ExportHandler`2[] handlers, TRequest request) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 200\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 229\\r\\n   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 130\\r\\n   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Stdio\\\\Host.cs:line 218\\r\\nSystem.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\r\\nFile name: 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'\\r\\n ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\r\\nFile name: 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'\\r\\n   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)\\r\\n   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)\\r\\n   at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)\\r\\n   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)\\r\\n   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)\\r\\nSystem.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\r\\nFile name: 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'\\r\\n ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.\\r\\nFile name: 'Microsoft.CodeAnalysis, Version=4.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'\\r\\n   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)\\r\\n   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)\\r\\n   at Microsoft.CodeAnalysis.DefaultAnalyzerAssemblyLoader.DirectoryLoadContext.Load(AssemblyName assemblyName)\\r\\n   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)\\r\\n   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)\"",
  "Body": null,
  "Seq": 31,
  "Type": "response"
}

Pretty sure this worked in the past.

Latest version of the extension, latest .NET 7

@thewhitewayofdelight
Copy link

Experiencing this issue as well

@thewhitewayofdelight
Copy link

thewhitewayofdelight commented Jul 16, 2023

Months passed already.

Just as Jonkelling said, it works normally on MacOS, but not on Windows. I don't know why...
I tried to use the same C# version and mono version from Mac OS, but still can't make it work on Windows.

@GrahamMThomas
Copy link

I'm currently experiencing this error after upgrading to .net 8

@MJLHThomassenHadrian
Copy link

I'm currently experiencing this error after upgrading to .net 8

Same here! How to fix this? Its pretty annoying.

@DanteMarshal
Copy link

DanteMarshal commented Jul 5, 2024

I get this in Unity, trying to load a DLL that I built myself and put right there in unity, with Full Paths set in the .csproj file.
I get similar errors with useModernDotNet either on or off.
I also get a not-so-similar but close-enough error when developing Asp.Net MVC that includes one or more Razor pages, I've made another issue for that.

The amount of time I've recently spent trying to make intellisense just work with CSharp is more than I've actually coded anything. I'm really considering changing my IDE or something.

@jonkelling
Copy link

jonkelling commented Jul 5, 2024

A while back there were a few changes, and since then everything has been working better.

  1. Visual Studio Code Editor package in Unity has been replaced by Visual Studio Editor package. Make sure you are up to date
  2. Make sure to Visual Studio Code is selected, or re-selected in Unity's External Tools Preferences after doing # 1. Regenerate project files.
  3. Use the latest C# and C# Dev Kit extensions in Visual Studio Code and make sure use modern .net is checked in VS Code settings
  4. Use the newest office Unity extension from Microsoft in VS Code.

@jonkelling
Copy link

I get this in Unity, trying to load a DLL that I built myself and put right there in unity

Make sure, if you're using assembly definitions, that your .asmdef file has the DLL listed in precompiledReferences

@DanteMarshal
Copy link

A while back there were a few changes, and since then everything has been working better.

  1. Visual Studio Code Editor package in Unity has been replaced by Visual Studio Editor package. Make sure you are up to date
  2. Make sure to Visual Studio Code is selected, or re-selected in Unity's External Tools Preferences after doing # 1. Regenerate project files.
  3. Use the latest C# and C# Dev Kit extensions in Visual Studio Code and make sure use modern .net is checked in VS Code settings
  4. Use the newest office Unity extension from Microsoft in VS Code.

Problem solved after installing visualstudiotoolsforunity.vstuc vscode extension !

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

10 participants