1
votes

I have a project with Output Type of Console Application that sometimes fails to start up when I debug. When this happens, may app starts to run and write to the vshost.exe console that is hosting the process being debugged. Then all of a sudden I will see a message in the Output window that says something like "The program '[13476] MyApp.vshost.exe' has exited with code -1 (0xffffffff)."

It doesn't happen every time, but when it does the Console Window my app started up in freezes on the screen and the debugger seems to halt. However, the vshost.exe process does not actually stop (I can see it in Task Manager with the same Process ID as the error message). It is as if Visual Studio thinks the process has exited, but it really has not. When I stop the debugger, the console window remains frozen on the screen as well. The only way to get the debugger to work again is to shutdown and restart VS.

This also happens if I have the Visual Studio hosting process turned off. The application only has one exit point in the Main method and when this happens a breakpoint on that line of code is not hit.

I cannot figure out how to get any more detail about why this is happening to troubleshoot further. I have put code in the AppDomain.CurrentDomain.UnhandledExcpetion handler as well as the Application.ApplicationExit handler, but they are not being hit when this problem occurs. I also don't see anything in the Windows event log, etc.

Output Window sample

...

'MyApp.vshost.exe' (CLR v4.0.30319: MyApp.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll'. Cannot find or open the PDB file.

'MyApp.vshost.exe' (CLR v4.0.30319: MyApp.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll'. Cannot find or open the PDB file.

'MyApp.vshost.exe' (CLR v4.0.30319: MyApp.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.ServiceModelSink\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.ServiceModelSink.dll'. Cannot find or open the PDB file.

'MyApp.vshost.exe' (CLR v4.0.30319: MyApp.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

The thread 0xf18 has exited with code 259 (0x103).

The thread 0x2928 has exited with code 259 (0x103).

The thread 0x3654 has exited with code 259 (0x103).

The program '[13476] MyApp.vshost.exe' has exited with code -1 (0xffffffff).

2
What you describe is all normal for VS2013, I see these exit codes as well for perfectly normally executing programs. And it is normal for vshost.exe to not exit. Just try it with a do-nothing new console mode project. That doesn't leave anything to guess why your program is misbehaving.Hans Passant
I'm not worried about the thread exits, it is the last line where MyApp.vshost.exe exists with a -1 code, but it is not hitting the exit point of my applicaiton.Dude0001

2 Answers

4
votes

I found the events below in the event log. However, it was in a weird spot I’ve never looked before Event Viewer -> Custom Views -> Administrative Events. This lead me to the MS KB http://support.microsoft.com/kb/2773443.

The MyApp project is targeting .NET 4.0 and I recently have installed Visual Studio 2013 on my laptop (.NET 4.5), which is around the time the issue started to occur. So I assume this is my issue.

What I don’t understand is why this exception wasn’t raising the AppDomain.UnhandledExcpetion event in my MyApp project and instead was silently terminating the process. The WCF service that was causing this issue was being started from a new thread that was being kicked off, but I think exceptions in this thread should still raise the AppDomain.UnhandledExcpetion event. I verified the UndhandledException handler is working in my application.

To resolve this, I have moved the startup of this service to its own project that targets .NET 3.5 and x86. This more mimics how we run the application in production anyway so it works for me. There is a patch and various work arounds in the Microsoft KB as well.

I hope this helps someone, I was beating my head against the wall trying to figure out how to even get the exception that was causing my issue.

Log Name:      Application
Source:        .NET Runtime
Date:          1/21/2014 9:09:23 AM
Event ID:      1026
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      DUDELT
Description:
Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ServiceModel.AddressAlreadyInUseException
Stack:
   at System.ServiceModel.Channels.TransportManager.Open(System.ServiceModel.Channels.TransportChannelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(System.ServiceModel.Channels.SelectTransportManagersCallback)
   at System.ServiceModel.Channels.TransportChannelListener.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.TcpChannelListener`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at System.ServiceModel.Channels.ReliableChannelListenerBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at System.ServiceModel.ServiceHostBase.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at MyApp32.MyApp32.Main()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name=".NET Runtime" />
    <EventID Qualifiers="0">1026</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2014-01-21T14:09:23.000000000Z" />
    <EventRecordID>287767</EventRecordID>
    <Channel>Application</Channel>
    <Computer>DUDELT</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ServiceModel.AddressAlreadyInUseException
Stack:
   at System.ServiceModel.Channels.TransportManager.Open(System.ServiceModel.Channels.TransportChannelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(System.ServiceModel.Channels.SelectTransportManagersCallback)
   at System.ServiceModel.Channels.TransportChannelListener.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.TcpChannelListener`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at System.ServiceModel.Channels.ReliableChannelListenerBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at System.ServiceModel.ServiceHostBase.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at MyApp32. MyApp 32.Main()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
</Data>
  </EventData>
</Event>

Log Name:      Application
Source:        Application Error
Date:          1/21/2014 9:09:23 AM
Event ID:      1000
Task Category: (100)
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      DUDELT
Description:
Faulting application name: MyApp.exe, version: 0.0.0.0, time stamp: 0x52dd9b89
Faulting module name: KERNELBASE.dll, version: 6.1.7601.18229, time stamp: 0x51fb1116
Exception code: 0xe0434352
Fault offset: 0x0000c41f
Faulting process id: 0x3ac0
Faulting application start time: 0x01cf16b23d49d636
Faulting application path: C:\MyApp\MyApp\bin\Debug\MyApp.exe
Faulting module path: C:\Windows\syswow64\KERNELBASE.dll
Report Id: a0b3e605-82a5-11e3-ab71-0021cc6f2033
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Application Error" />
    <EventID Qualifiers="0">1000</EventID>
    <Level>2</Level>
    <Task>100</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2014-01-21T14:09:23.000000000Z" />
    <EventRecordID>287768</EventRecordID>
    <Channel>Application</Channel>
    <Computer>DUDELT</Computer>
    <Security />
  </System>
  <EventData>
    <Data>MyApp.exe</Data>
    <Data>0.0.0.0</Data>
    <Data>52dd9b89</Data>
    <Data>KERNELBASE.dll</Data>
    <Data>6.1.7601.18229</Data>
    <Data>51fb1116</Data>
    <Data>e0434352</Data>
    <Data>0000c41f</Data>
    <Data>3ac0</Data>
    <Data>01cf16b23d49d636</Data>
    <Data>C:\code\MyApp\MyApp\bin\Debug\MyApp.exe</Data>
    <Data>C:\Windows\syswow64\KERNELBASE.dll</Data>
    <Data>a0b3e605-82a5-11e3-ab71-0021cc6f2033</Data>
  </EventData>
</Event>
0
votes

I hit the same issue, and it looks a .net undocumented issue. But you can mitigate it as follow:

  • find the portion of code that fail, and follow the class that you try to read.
  • add a default constructor for that class. The serialization in some case needs a default constructor to create the objects, and this is the actual issue.

Hope this works for future generations who will search for this error! :)

D