VS 2022更新后加载项目报错:Application.xaml不属于任何项目
问题描述
向项目添加资源时加载报错,刚更新Visual Studio Pro 2022 64位(17.3.5),不确定是否因此引发问题。查看一个多月的备份,项目中从未有过Application.xaml文件,执行清理、重建操作后无效。
报错详情
===================== 2022年10月5日 上午11:42:01 可恢复错误 Microsoft.VisualStudio.ProjectSystem.Query.QueryExecutionException: 文件 P:\Projects\MyPortal\MyPortal\Application.xaml 不属于解决方案中的任何项目,无法打开。请将该文件添加到项目后重试。 ---> System.ArgumentException: 文件 P:\Projects\MyPortal\MyPortal\Application.xaml 不属于解决方案中的任何项目,无法打开。请将该文件添加到项目后重试。 在 Microsoft.VisualStudio.Shell.Design.Serialization.DocData..ctor(IServiceProvider provider, String fileName) 在 Microsoft.VisualStudio.ProjectSystem.VS.WPF.ApplicationXamlFileAccessor.<TryGetApplicationXamlFileAsync>g__GetDocDataAsync|11_0>d.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.WPF.ApplicationXamlFileAccessor.<TryGetApplicationXamlFileAsync>d__11.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.WPF.ApplicationXamlFileAccessor.<GetStartupUriAsync>d__7.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.Properties.WPFValueProvider.<GetPropertyValueAsync>d__10.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.Properties.InterceptedProjectProperties.<GetUnevaluatedPropertyValueAsync>d__3.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.PropertyPages.PageProperty.<GetUnevaluatedValueFromDataSourceAsync>d__41.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.Query.UIPropertyValueDataProducer.<CreateUIPropertyValueValueAsync>d__1.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.Query.UIPropertyValueDataProducer.<CreateUIPropertyValueValueAsync>d__0.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.Query.UIPropertyValueDataProducer.<CreateUIPropertyValueValuesAsync>d__2.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.Query.QueryDataFromProviderStateProducerBase`1.<SendRequestAsync>d__0.MoveNext() --- 内部异常堆栈跟踪的末尾 --- 在 Microsoft.VisualStudio.ProjectSystem.Query.QueryExecution.QuerySubscription`1.<RunQueryOnceAsync>d__9.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.Query.QueryExecution.QuerySubscription`1.<>c__DisplayClass8_0.<<Start>b__0>d.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<InitializeAsync>d__10.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 在 Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<CreateAsync>d__9.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertiesEditor.<>c__DisplayClass0_0.<<-ctor>b__0>d.MoveNext() --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.AsyncLoadContent.<>c__DisplayClass0_0.<<Initialize>b__0>d.MoveNext() ===================
解决方案
- 检查项目的
.csproj配置文件,查找是否存在引用Application.xaml的节点(比如<ApplicationDefinition>),如果有直接删除该配置项 - 手动创建空的
Application.xaml文件并添加到项目中,后续可根据需求修改或移除——部分WPF项目需要该文件作为入口,VS更新后可能强制校验这个文件的存在 - 重置Visual Studio设置:打开VS,依次点击
工具->导入和导出设置->重置所有设置,选择默认配置后重启 - 清除VS缓存:删除以下路径的缓存文件后重启VS
%LOCALAPPDATA%\Microsoft\VisualStudio\17.0_xxxx\ComponentModelCache%USERPROFILE%\AppData\Local\Temp\VisualStudioProjectSystem
- 回滚VS版本:如果确定是更新到17.3.5后出现的问题,可通过VS Installer卸载该更新,安装之前的稳定版本
内容的提问来源于stack exchange,提问作者Willy
相关产品推荐
相关产品推荐

