1

So I have 3 WPF applications that are fully functional and run fine with the debugger in Visual Studio. However 2 of the three will not run at all without the debugger (aka the .exe does nothing). It doesn't crash or give me errors it just gives me a second of loading wheel and then nothing. I don't understand why it would work fine running with the debugger and not run at all when it is run without it. I have tried both the debug and release versions and it didn't make a difference. I have tried restarting both visual studio and my computer and cleaning and rebuilding the solution. I mention the application that works fine because it leads me to believe my visual studio is working fine. I'm using Visual Studio 2013.

I don't know what code snippets to show because I have no idea what could be causing the issue. If you would like to see certain functions/files let me know in the comments and I will add them to the post if I can.

Do you have any idea what could be causing this to happen and what steps I need to take to get my .exe files running the way the .vshost.exe runs with the debugger?

EDIT: The application is indeed throwing an error which I found in eventlogs. Though I am still unsure what is causing the error This is the error:

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()

EDIT 2: My coworker ran the .exe and got a more verbose error message:

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()

EDIT 3: Thanks to help from user Jay T, I discovered that the aero assembly was being loaded when running with the debugger, but not without it since I am running on an windows 8 machine and they switched over to a new aero2 assembly. Removing the assembly and references to it allowed the .exe to run without crashing

Gordon Allocman
  • 768
  • 7
  • 23
  • Do you have to attach the debugger to make it work? Are you able to run the debug build without visual studio? – empi Feb 25 '16 at 19:32
  • Do you applications have any sort of logging? Have you tried using Fusion logs to verify your application and its dependencies are all being loaded? See http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net for help on Fusion logs. – Mikanikal Feb 25 '16 at 19:32
  • I googled your title which came up with this: http://stackoverflow.com/questions/4206941/wpf-dotnet-application-will-run-in-debug-mode-but-exe-will-not-run For that guy he checked is Application event log and found that the program was throwing an exception which for unknown reasons wasn't throwing in debug mode. If you go to "Project->{your project} Properties" you can find differences between debug/release, such as "Command line arguments". – Quantic Feb 25 '16 at 19:33
  • @empi Yes the debugger has to be attached, even for the program that the .exe works on the .vshost.exe doesnt work without vs, which I assume to be the way it is supposed to be – Gordon Allocman Feb 25 '16 at 19:38
  • @Quantic I searched for a while and didn't see this post, I'm running through the suggested solutions now and seeing if any of them work – Gordon Allocman Feb 25 '16 at 19:39

2 Answers2

3

To start to narrow down the cause of your issue, you could put in an application level exception handler and popup a MessageBox with the exception info or write it out to a file. In your App.xaml file add a handler for 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>

Then in App.xaml.cs you can handle the event and get access to the unhandled exception:

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

In that function, you could show the exception message in a MessageBox, write it out and the stack trace to a text file using StreamWriter, etc. You won't have to run the application in Debug mode, so you'll be able to see what's causing the problem in that environment. Feel free to post the exception information if you need more help solving the problem.

Jay T
  • 853
  • 10
  • 11
  • I posted the exception they are throwing in the question, both programs seem to be throwing the same thing – Gordon Allocman Feb 25 '16 at 19:52
  • It looks like there's then in your XAML. Judging from the fact that it's happening only outside of Visual Studio, I wonder if there are maybe some resources (images, icons, etc.) that are missing, or are not getting copied over to the directory you're running the application from. Are you running the EXE file from the same directory the application was built or did you copy it somewhere else? – Jay T Feb 25 '16 at 19:57
  • I am running from same folder it is built in, I added some more exception information in the question – Gordon Allocman Feb 25 '16 at 20:02
  • There are a few calls in the stack trace that have to do with web calls (WpfWebRequestHelper, PackWebResponse). I'm not familiar with them, but are you making any web calls in your application during startup, or in your XAML? – Jay T Feb 25 '16 at 20:07
  • The only external access I am doing is to a database using the sqlConnection class – Gordon Allocman Feb 25 '16 at 20:09
  • Nevermind, now that I look at the top most call, it looks like maybe it can't find an assembly it's trying to load. Are you referencing any external assemblies? In the past I've used [Procmon](https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx) to track assemblies that couldn't be found. You could give that a shot, just start tracking right before you start your program and then filter the events based on your process name since it tracks a lot of other Windows and program events. – Jay T Feb 25 '16 at 20:22
  • You sir are a life saver! I was referencing aero for the look, but I am on a windows 8 machine so I believe I need to reference aero2 or something like that. I removed the aero assembly and it runs fine now. Thank you very much! – Gordon Allocman Feb 25 '16 at 20:29
  • No problem, glad I could help! I've run into that problem before with referencing Aero. – Jay T Feb 26 '16 at 16:59
0

In my case i referenced PresentationFramework.Aero . so to fix the error i made Copy Local true for PresentationFramework.Aero and PresentationFramework. it works after that.

Sagar V
  • 12,158
  • 7
  • 41
  • 68
Shanaka Rusith
  • 421
  • 1
  • 4
  • 19