升级 vs2019 后,以及安装 vs2020 后,我无法打开 C# 项目。每当我尝试打开时,我都会收到第一个错误框,通知 VS 无法加载 RoselynPackage 和 CSharpPackage,之后在输出中我会收到如下错误消息 project 'Assembly-CSharp' 无法打开,因为 Visual C#无法创建 2022 语言服务。值没有落在预期范围内。
尝试了建议的方法来删除 \AppData\Local\Microsoft\VisualStudio .0_064520ec\ComponentModelCache 并清理 nuget 等(如何修复 Microsoft Visual Studio 错误:“包未正确加载”?)缓存,但似乎没有任何效果帮助。
还尝试了此处建议的内容调试时调用 COM 组件 VS2012 返回了错误 HRESULT E_FAIL
尝试修复。尝试清理 Visual Studio 并重新安装,也没有帮助。
发现如果我在 Windows 上创建一个新帐户并从那里打开 Visual Studio,它就可以正常工作。仅在我的帐户中不起作用。注册表问题?
这是我在活动日志中得到的内容。
<entry>
<record>395</record>
<time>2022/01/17 10:48:34.049</time>
<type>Information</type>
<source>VisualStudio</source>
<description>Begin package load [RoslynPackage]</description>
<guid>{6CF2E545-6109-4730-8883-CF43D7AEC3E1}</guid>
</entry>
<entry>
<record>396</record>
<time>2022/01/17 10:48:34.058</time>
<type>Error</type>
<source>Microsoft.VisualStudio.LanguageServices.Setup.RoslynPackage</source>
<description>Exception occurred while loading solution options: System.Runtime.InteropServices.COMException (0x80030002): could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND))
 at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
 at Microsoft.VisualStudio.Shell.Package.Initialize()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)</description>
</entry>
<entry>
<record>397</record>
<time>2022/01/17 10:48:34.371</time>
<type>Information</type>
<source>VisualStudio</source>
<description>Begin package load [ErrorListPackage]</description>
<guid>{4A9B7E50-AA16-11D0-A8C5-00A0C921A4D2}</guid>
</entry>
<entry>
<record>398</record>
<time>2022/01/17 10:48:34.395</time>
<type>Error</type>
<source>VisualStudio</source>
<description>SetSite failed for package [RoslynPackage]Source: 'mscorlib' Description: Illegal characters in path.
System.ArgumentException: Illegal characters in path.
 at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
 at System.IO.Path.Combine(String path1, String path2, String path3, String path4)
 at Microsoft.CodeAnalysis.Internal.Log.FileLogger..ctor(IGlobalOptionService optionService)
 at Microsoft.VisualStudio.LanguageServices.Telemetry.VisualStudioWorkspaceTelemetryService.CreateLogger(TelemetrySession telemetrySession)
 at Microsoft.VisualStudio.LanguageServices.Telemetry.AbstractWorkspaceTelemetryService.InitializeTelemetrySession(TelemetrySession telemetrySession)
 at Microsoft.VisualStudio.LanguageServices.Setup.RoslynPackage.<InitializeAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.VisualStudio.Shell.AsyncPackage.<>c__DisplayClass20_0.<<Microsoft-VisualStudio-Shell-Interop-IAsyncLoadablePackageInitialize-Initialize>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.VisualStudio.Threading.JoinableTask.<JoinAsync>d__76.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at Microsoft.VisualStudio.Services.VsTask.RethrowException(AggregateException e)
 at Microsoft.VisualStudio.Services.VsTask.InternalGetResult(Boolean ignoreUIThreadCheck)</description>
<guid>{6CF2E545-6109-4730-8883-CF43D7AEC3E1}</guid>
<hr>80070057 - E_INVALIDARG</hr>
<errorinfo></errorinfo>
</entry>
<entry>
<record>399</record>
<time>2022/01/17 10:48:34.416</time>
<type>Error</type>
<source>VisualStudio</source>
<description>End package load [RoslynPackage]</description>
<guid>{6CF2E545-6109-4730-8883-CF43D7AEC3E1}</guid>
<hr>80070057 - E_INVALIDARG</hr>
<errorinfo></errorinfo>
</entry>
<entry>
<record>400</record>
<time>2022/01/17 10:48:34.505</time>
<type>Information</type>
<source>VisualStudio</source>
<description>End package load [Microsoft.VisualStudio.PlatformUI.UIContextRules.ContextRuleMonitorPackage]</description>
<guid>{8AA75F1E-7410-4EFE-82AA-0FEA79A0A042}</guid>
</entry>
<entry>
<record>401</record>
<time>2022/01/17 10:48:34.525</time>
<type>Information</type>
<source>VisualStudio</source>
<description>End package load [ErrorListPackage]</description>
<guid>{4A9B7E50-AA16-11D0-A8C5-00A0C921A4D2}</guid>
</entry>
<entry>
<record>402</record>
<time>2022/01/17 10:48:34.612</time>
<type>Warning</type>
<source>GlobalBrokeredServiceContainer</source>
<description>Request for "Microsoft.VisualStudio.Shell.Internal.SettingsManager (1.0)" from Process denied because the service is only exposed RemoteExclusiveClient, LiveShareGuest.</description>
</entry>
<entry>
<record>403</record>
<time>2022/01/17 10:48:34.612</time>
<type>Warning</type>
<source>GlobalBrokeredServiceContainer</source>
<description>Request for proxy to "Microsoft.VisualStudio.Shell.Internal.SettingsManager (1.0)" is declined: ServiceAudienceMismatch.</description>
</entry>
<entry>
<record>404</record>
<time>2022/01/17 10:48:34.618</time>
<type>Information</type>
<source>VisualStudio</source>
<description>Begin package load [Microsoft.VisualStudio.Editor.Implementation.EditorPackage]</description>
<guid>{E269B994-EF71-4CE0-8BCD-581C217372E8}</guid>
</entry>
<entry>
<record>405</record>
<time>2022/01/17 10:48:34.619</time>
<type>Information</type>
<source>VisualStudio</source>
<description>Begin package load [Global Hub Client Package]</description>
<guid>{11AD60FC-6D87-4674-8F88-9ABE79176CBE}</guid>
</entry>
<entry>
<record>406</record>
<time>2022/01/17 10:48:34.688</time>
<type>Information</type>
<source>VisualStudio</source>
<description>Begin package load [Text Management Package]</description>
<guid>{F5E7E720-1401-11D1-883B-0000F87579D2}</guid>
</entry>
<entry>
<record>407</record>
<time>2022/01/17 10:48:34.693</time>
<type>Information</type>
<source>VisualStudio</source>
<description>End package load [Text Management Package]</description>
<guid>{F5E7E720-1401-11D1-883B-0000F87579D2}</guid>
</entry>
<entry>
<record>408</record>
<time>2022/01/17 10:48:34.811</time>
<type>Information</type>
<source>VisualStudio</source>
<description>End package load [Microsoft.VisualStudio.Editor.Implementation.EditorPackage]</description>
<guid>{E269B994-EF71-4CE0-8BCD-581C217372E8}</guid>
</entry>
<entry>
<record>409</record>
<time>2022/01/17 10:48:34.876</time>
<type>Information</type>
<source>VisualStudio</source>
<description>End package load [Global Hub Client Package]</description>
<guid>{11AD60FC-6D87-4674-8F88-9ABE79176CBE}</guid>
</entry>
<entry>
<record>410</record>
<time>2022/01/17 10:48:35.397</time>
<type>Information</type>
<source>Extension Manager</source>
<description>IncompatibilityList - Call Servicehub for downloading compatibility list file.</description>
</entry>
<entry>
<record>411</record>
<time>2022/01/17 10:48:35.844</time>
<type>Information</type>
<source>Extension Manager</source>
<description>IncompatibilityList - Look for incompatible extensions.Configuration or the user compatibility list file changed</description>
</entry>
<entry>
<record>412</record>
<time>2022/01/17 10:48:41.362</time>
<type>Information</type>
<source>VisualStudio</source>
<description>Begin package load [Microsoft.VisualStudio.Services.ToastNotifications.ToastNotificationsPackage]</description>
<guid>{C931D979-CA1A-41E8-8A23-E86B85E3141B}</guid>
</entry>
<entry>
<record>413</record>
<time>2022/01/17 10:48:41.365</time>
<type>Information</type>
<source>VisualStudio</source>
<description>End package load [Microsoft.VisualStudio.Services.ToastNotifications.ToastNotificationsPackage]</description>
<guid>{C931D979-CA1A-41E8-8A23-E86B85E3141B}</guid>
</entry>
<entry>
<record>414</record>
<time>2022/01/17 10:48:43.821</time>
<type>Error</type>
<source>VisualStudio</source>
<description>SetSite failed for package [CSharpPackage]Source: 'Microsoft.VisualStudio.Interop' Description: Value does not fall within the expected range.
System.ArgumentException: Value does not fall within the expected range.
 at Microsoft.VisualStudio.Shell.Interop.IVsTaskBody.DoWork(IVsTask pTask, UInt32 dwCount, IVsTask[] pParentTasks, Object& pResult)
 at Microsoft.VisualStudio.Services.VsTask.<>c__DisplayClass86_0.<GetCallbackForMultipleParent>b__0(Task`1[] _)
 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
 at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at Microsoft.VisualStudio.Services.VsTask.RethrowException(AggregateException e)
 at Microsoft.VisualStudio.Services.VsTask.InternalGetResult(Boolean ignoreUIThreadCheck)
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at Microsoft.VisualStudio.Services.VsTask.RethrowException(AggregateException e)
 at Microsoft.VisualStudio.Services.VsTask.InternalGetResult(Boolean ignoreUIThreadCheck)
 at Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService.AbstractPackage`2.<InitializeAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.VisualStudio.LanguageServices.CSharp.LanguageService.CSharpPackage.<InitializeAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.VisualStudio.Shell.AsyncPackage.<>c__DisplayClass20_0.<<Microsoft-VisualStudio-Shell-Interop-IAsyncLoadablePackageInitialize-Initialize>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
 at Microsoft.VisualStudio.Shell.UIThreadReentrancyScope.WaitOnTaskCompleteInternal(Task task, CancellationToken cancel, Int32 ms)
 at Microsoft.VisualStudio.Services.VsTask.<>c__DisplayClass68_1.<InternalGetResult>b__1()
 at Microsoft.VisualStudio.Services.VsTask.IgnoreObjectDisposedException(Action action)
 at Microsoft.VisualStudio.Services.VsTask.<>c__DisplayClass68_0.<InternalGetResult>b__0()
 at Microsoft.VisualStudio.Services.VsTask.<>c__DisplayClass76_0.<InvokeWithWaitDialog>b__0()
 at Microsoft.VisualStudio.Services.VsTask.InvokeWithWaitDialog[T](Func`1 function)
 at Microsoft.VisualStudio.Services.VsTask.InternalGetResult(Boolean ignoreUIThreadCheck)</description>
<guid>{13C3BBB4-F18F-4111-9F54-A0FB010D9194}</guid>
<hr>80070057 - E_INVALIDARG</hr>
<errorinfo></errorinfo>
</entry>
<entry>
<record>415</record>
<time>2022/01/17 10:48:43.832</time>
<type>Error</type>
<source>VisualStudio</source>
<description>End package load [CSharpPackage]</description>
<guid>{13C3BBB4-F18F-4111-9F54-A0FB010D9194}</guid>
<hr>80070057 - E_INVALIDARG</hr>
<errorinfo></errorinfo>
</entry>## Heading ##
对我有用的是进入 VS 2022 的选项“NuGet Package Manager > General”。我单击“清除所有 NuGet 存储”,并确保选择了“允许 NuGet 下载丢失的包”和“在 Visual Studio 中构建期间自动检查丢失的包”选项。然后我重新启动 VS 2022,一切都很好。
单击“确定”按钮并重新启动 VS 后,我注意到我的 NuGet.config 文件已更改为:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
至:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<packageManagement>
<add key="format" value="0" />
<add key="disabled" value="False" />
</packageManagement>**
</configuration>
我的 NuGet.config 文件位于此处:
C:\Users{用户}\AppData\Roaming\NuGet\NuGet.config