c# - IOException 未处理 - 找不到资源 app.xaml

标签 c# .net wpf visual-studio-2010

在我的一个 WPF 项目中,当我打开解决方案并在调试时启动它时出现此错误。如果我重建解决方案并重新启动它,错误就会消失。

我通过删除 App.xaml 中的 StartUpUri 实现了对应用程序的命令行支持:

WPF Command Line

如何摆脱这个烦人的错误?

使用 VS 2010.net 4.0

enter image description here

System.IO.IOException was unhandled
  Message=Cannot locate resource 'app.xaml'.
  Source=PresentationFramework
  StackTrace:
       at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
       at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
       at System.IO.Packaging.PackagePart.GetStream()
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at ESPS3.ServerSchemaUtility.App.InitializeComponent() in e:\ESP3.0\InternalTools\ServerSchemaUtility\ServerSchemaUtility\App.xaml:line 1
       at ESPS3.ServerSchemaUtility.App.Main() in E:\ESP3.0\InternalTools\ServerSchemaUtility\ServerSchemaUtility\obj\x86\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

最佳答案

我以前在从 VS 2005 移植到 2008 时见过这个错误。在 2010 年从未见过。 由于某种原因,app.xaml 的build设置丢失了。所以你可以检查 app.xaml 的属性。附图中显示了正确的设置。

app.xaml properties

另一方面,如果您使用的是 MVVC,则可能是其他原因,如下所述:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/39d7a4dd-9034-4ae8-843c-ccd4940ba51c/

关于c# - IOException 未处理 - 找不到资源 app.xaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7126147/

相关文章:

WPF MVVM : ComboBox height is different for integers

c# - 在 C# 中重用数组

c# - 从绑定(bind)到我的 XAML 中的事件调用我的 ViewModel 中的命令?

Javascript If语句运行一些html代码

c# - 如何防止我的代码被盗?

WPF 控制翻转

c# - 如何使用C#在asp.net页面中的服务器上显示自定义的弹出消息框

c# - 我应该如何使用多线程正确调用 Web 浏览器?

c# - 上下文菜单的 WPF 子菜单

c# - 为什么在 .NET 4.6 中更改 WPF DataGrid ItemsSource 如此缓慢?