【问题标题】:WPF applications running with debugger, but not without使用调试器运行的 WPF 应用程序,但并非没有
【发布时间】:2017-06-14 00:26:52
【问题描述】:

所以我有 3 个 WPF 应用程序,它们功能齐全,可以在 Visual Studio 中使用调试器正常运行。然而,如果没有调试器,这三个中的两个根本不会运行(也就是 .exe 什么都不做)。它不会崩溃或给我错误,它只会给我一秒钟的加载轮,然后什么也没有。我不明白为什么它可以与调试器一起正常运行,而在没有它的情况下运行时根本无法运行。我已经尝试了调试和发布版本,但没有任何区别。我尝试重新启动 Visual Studio 和我的计算机并清理和重建解决方案。我提到了运行良好的应用程序,因为它让我相信我的视觉工作室运行良好。我正在使用 Visual Studio 2013。

我不知道要显示什么代码 sn-ps,因为我不知道是什么导致了问题。如果您想查看某些功能/文件,请在 cmets 中告诉我,如果可以,我会将它们添加到帖子中。

您知道什么可能导致这种情况发生吗?我需要采取哪些步骤才能让我的 .exe 文件以 .vshost.exe 与调试器一起运行的方式运行?

编辑:该应用程序确实抛出了我在事件日志中发现的错误。虽然我仍然不确定是什么导致了错误 这是错误:

Application: OrderFinderTool.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Windows.Markup.XamlParseException
Stack:
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadComponent(System.Object, System.Uri)
   at SupportWizard.App.InitializeComponent()
   at SupportWizard.App.Main()

编辑 2: 我的同事运行 .exe 并收到更详细的错误消息:

Application: OrderFinderTool.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.Assembly.Load(System.Reflection.AssemblyName)
   at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(System.String, System.String, System.String)
   at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(System.Uri, System.String ByRef, Boolean ByRef)
   at MS.Internal.AppModel.ResourceContainer.GetPartCore(System.Uri)
   at System.IO.Packaging.Package.GetPartHelper(System.Uri)
   at System.IO.Packaging.Package.GetPart(System.Uri)
   at System.IO.Packaging.PackWebResponse+CachedResponse.GetResponseStream()
   at System.IO.Packaging.PackWebResponse.GetResponseStream()
   at System.IO.Packaging.PackWebResponse.get_ContentType()
   at MS.Internal.WpfWebRequestHelper.GetContentType(System.Net.WebResponse)
   at MS.Internal.WpfWebRequestHelper.GetResponseStream(System.Net.WebRequest, MS.Internal.ContentType ByRef)
   at System.Windows.ResourceDictionary.set_Source(System.Uri)
   at System.Windows.Baml2006.WpfSharedBamlSchemaContext+<>c.<Create_BamlProperty_ResourceDictionary_Source>b__342_0(System.Object, System.Object)
   at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(System.Object, System.Object)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Xaml.XamlMember, System.Object, System.Object)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Object, System.Xaml.XamlMember, System.Object)

Exception Info: System.Windows.Markup.XamlParseException
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadComponent(System.Object, System.Uri)
   at OrderFinderTool.App.InitializeComponent()
   at OrderFinderTool.App.Main()

编辑 3: 感谢用户 Jay T 的帮助,我发现使用调试器运行时正在加载 aero 程序集,但并非没有它,因为我在 Windows 8 机器上运行并且他们切换到了新的 aero2 程序集。删除程序集和对其的引用允许 .exe 运行而不会崩溃

【问题讨论】:

  • 是否必须附加调试器才能使其工作?你能在没有 Visual Studio 的情况下运行调试版本吗?
  • 您的应用程序有任何类型的日志记录吗?您是否尝试过使用 Fusion 日志来验证您的应用程序及其依赖项是否都已加载?有关 Fusion 日志的帮助,请参阅 stackoverflow.com/questions/255669/…
  • 我用谷歌搜索了你的标题:stackoverflow.com/questions/4206941/… 他检查的那个人是应用程序事件日志,发现程序抛出了一个异常,由于未知原因没有在调试模式下抛出.如果您转到“Project->{your project} Properties”,您可以找到调试/发布之间的差异,例如“命令行参数”。
  • @empi 是的,必须附加调试器,即使对于 .exe 在 .vshost.exe 上运行的程序,如果没有 vs 也无法运行,我认为这是应该的方式
  • @Quantic 我搜索了一段时间并没有看到这篇文章,我现在正在运行建议的解决方案,看看它们是否有效

标签: c# wpf visual-studio-2013


【解决方案1】:

要开始缩小问题的原因,您可以放入应用程序级异常处理程序并弹出带有异常信息的 MessageBox 或将其写入文件。在您的 App.xaml 文件中添加 DispatcherUnhandledExceptption 的处理程序:

<Application x:Class="YourApp"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             
         StartupUri="MainWindow.xaml"
         DispatcherUnhandledException="Application_DispatcherUnhandledException">

</Application>

然后在 App.xaml.cs 中您可以处理事件并访问未处理的异常:

private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
        var exception = e.Exception;
}

在该函数中,您可以在 MessageBox 中显示异常消息,使用 StreamWriter 等将其写出并将堆栈跟踪记录到文本文件中。您不必在调试模式下运行应用程序,因此您将能够看到在该环境中导致问题的原因。如果您需要更多帮助来解决问题,请随时发布异常信息。

【讨论】:

  • 我发布了他们在问题中抛出的异常,两个程序似乎都抛出了同样的东西
  • 看起来你的 XAML 中就有。从它只发生在 Visual Studio 之外的事实来看,我想知道是否可能有一些资源(图像、图标等)丢失,或者没有被复制到您运行应用程序的目录中。您是从构建应用程序的同一目录运行 EXE 文件还是将其复制到其他地方?
  • 我从它内置的同一个文件夹中运行,我在问题中添加了更多异常信息
  • 堆栈跟踪中有一些调用与 Web 调用(WpfWebRequestHelper、PackWebResponse)有关。我对它们不熟悉,但您是在启动期间在应用程序中还是在 XAML 中进行任何 Web 调用?
  • 我正在做的唯一外部访问是使用 sqlConnection 类访问数据库
【解决方案2】:

就我而言,我引用了 PresentationFramework.Aero 。因此,为了修复错误,我将 PresentationFramework.AeroPresentationFramework 的 Copy Local 设置为 true。之后就可以了。

【讨论】:

    猜你喜欢
    • 2010-10-18
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多