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

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

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>

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

Related

Different versions of ClickOnce application cause crash due to missing original UI.exe file

I´m having a problem with ClickOnce releases:
We need three versions of a program installed via ClickOnce on every machine, each having different settings: Production, Pilot and Test
What we do is use a self programmed release manager that deploys every version in a different network drive location using MSBuild
Installation of every version works out fine, but program crashes when being run.
The ApplicationName is changed while running MSBuild and I have found that the application is still looking for the original UI.exe whilst the name of the Application has changed to e.g. UITest.exe
If I copy the UI.exe to the installation folder and then run UITest.exe the program works as it should.
What am I missing? How can I get rid of the need of the original UI.exe?
Background Infos:
To be able to release three different versions via MSBuild we use an additional ".target" file that is implemented in UI.csproj after the build property groups like this:
<Import Project="CustomBuild.targets" />
The CustomBuild.targets file looks like this:
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishType>none</PublishType>
</PropertyGroup>
<Choose>
<When Condition="'$(PublishType)' == 'production'">
<PropertyGroup>
<PublishUrl>\\netapp1\users\ClickOnce\Production\</PublishUrl>
<InstallUrl>\\netapp1\users\ClickOnce\Production\</InstallUrl>
<PublishDir>\\netapp1\users\ClickOnce\Production\</PublishDir>
<ProductName>UI Production</ProductName>
<AssemblyName>UIProd</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Prod</UIExchangeSettingsPath>
</PropertyGroup>
</When>
<When Condition=" '$(PublishType)' == 'pilot' ">
<PropertyGroup>
<PublishUrl>\\netapp1\users\ClickOnce\Pilot\</PublishUrl>
<InstallUrl>\\netapp1\users\ClickOnce\Pilot\</InstallUrl>
<PublishDir>\\netapp1\users\ClickOnce\Pilot\</PublishDir>
<ProductName>UI Pilot</ProductName>
<AssemblyName>UIPilot</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Pilot</UIExchangeSettingsPath>
</PropertyGroup>
</When>
<When Condition=" '$(PublishType)' == 'test' ">
<PropertyGroup>
<PublishUrl>\\netapp1\users\ClickOnce\Test\</PublishUrl>
<InstallUrl>\\netapp1\users\ClickOnce\Test\</InstallUrl>
<PublishDir>\\netapp1\users\ClickOnce\Test\</PublishDir>
<ProductName>UI Test</ProductName>
<AssemblyName>UITest</AssemblyName> -- AssemblyName is changed here
<UIExchangeSettingsPath>..\_UIExchangeSettings\Test</UIExchangeSettingsPath>
</PropertyGroup>
</When>
</Choose>
</Project>
Then the MSBuild Process is called within a batch file like this:
#echo off
set branch=%1
set publishtype=%2
echo Rebuilding UI project and publishing as new %publishtype% version...
>output.txt (
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\MSBuild.EXE" "C:\Projects\%branch%\UI" /p:SolutionDir="C:\Projects\%branch%\\" /p:PlatformTarget=x86 /p:Configuration=Release /p:PublishType=%publishtype% /t:rebuild /t:publish
)
When running the installed programs they crash and show the following exceptions in the windows event log:
Log Name: Application
Source: .NET Runtime
Date: 11.11.2020 10:02:58
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: vw8-te-012.***.intranet
Description:
Application: UIProd.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 UI.App.InitializeComponent()
at UI.App.Main()
and
Log Name: Application
Source: Application Error
Date: 11.11.2020 10:02:58
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Computer: vw8-te-012.***.intranet
Description:
Faulting application name: UIProd.exe, version: 1.0.0.0, time stamp: 0x5faba858
Faulting module name: KERNELBASE.dll, version: 6.3.9600.17031, time stamp: 0x53088860
Exception code: 0xe0434352
Fault offset: 0x00014dbd
Faulting process ID: 0x3594
Faulting application start time: 0x01d6b80972f79f7d
Faulting application path: C:\Users\***\AppData\Local\Apps\2.0\XNQORKVG.2DT\5A4N7BAY.11G\uipr..tion_e9badd1d426758be_0001.0001_0a1650216431b128\UIProd.exe
Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
Report ID: b1090c1f-23fc-11eb-82ef-0050568fb707
Faulting package full name:
Faulting package-relative application ID:
Turns out it was a reference to a resource dictionary in App.xaml causing the problem.
Wrong implementation:
<ResourceDictionary Source="pack://application:,,,/UI;component/Resources/PlcBuildResources.xaml" />
Corrected implementation:
<ResourceDictionary Source="../Resources/PlcBuildResources.xaml"/>
Lesson learned: Be careful when referencing resource dictionaries or other files using the assembly name in the reference. If the assembly name is changed when building via MSBuild as in my case, the referenced file will not be found and cause the application to crash.

The process was terminated due to an unhandled exception - WCF service

So I have a WCF service that i created that gets messages from customer and parses them to desired output and sends them to other customer via TCP/HTTP/FTP etc.
This windows service has long running threads for each customer created using TPL's.
So for logging I have used NLOG, log to file and event viewer with below configurations
<target xsi:type="File" name="flatfile" layout="${longdate} ${uppercase:${level}} ${message} ${exception:format=tostring,StackTrace}"
archiveAboveSize="2000000" archiveFileName="${basedir}/logs/archive/${shortdate}-{#####}.engine.log" archiveNumbering="Sequence" archiveEvery="None"
maxArchiveFiles="100" fileName="${basedir}/logs/engine.current.log" keepFileOpen="true" concurrentWrites="true" />
<target xsi:type="EventLog" name="eventlog" layout="${longdate} ${uppercase:${level}} ${message} ${exception:format=tostring} ${StackTrace}" log="Application" source="Nuance Interface Engine Service" eventId="${event-properties:EventID}" />
Even when I added concurrentWrites="true", when I start WCF service after 20+ hours of time passes I got below error in event viewer
Application: MyWcfService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.OutOfMemoryException
at System.Text.StringBuilder..ctor(System.String, Int32, Int32, Int32)
at NLog.Layouts.SimpleLayout.GetFormattedMessage(NLog.LogEventInfo)
at NLog.Targets.FileTarget.GetFormattedMessage(NLog.LogEventInfo)
at NLog.Targets.FileTarget.GetBytesToWrite(NLog.LogEventInfo)
at NLog.Targets.FileTarget.Write(NLog.Common.AsyncLogEventInfo[])
at NLog.Targets.Target.WriteAsyncLogEvents(NLog.Common.AsyncLogEventInfo[])
at NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(System.Object)
at System.Threading.TimerQueueTimer.CallCallbackInContext(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.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireQueuedTimerCompletion(System.Object)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Could you please someone guide me on where this issue is occuring, I thought multiple threads are accessing this log file hence I added concurrentWrites="true" attribute to nlog's file target.
after 1 second passes to above error, I see one more error in my event viewer.
Faulting application name: Hl7ic.Engine.View.exe, version: 18.0.1.160, time stamp: 0x5af5cd1f
Faulting module name: KERNELBASE.dll, version: 6.3.9600.18938, time stamp: 0x5a7dd8a7
Exception code: 0xe0434352
Fault offset: 0x00015ef8
Faulting process id: 0x1074
Faulting application start time: 0x01d3ea7338d9851c
Faulting application path: C:\Program Files (x86)\MyServices\MyWcfService.exe
Faulting module path: C:\windows\SYSTEM32\KERNELBASE.dll
Report Id: 59b36929-5688-11e8-80ca-005056a80aaa
Faulting package full name:
Faulting package-relative application ID:
OutOfMemoryException means that there is not enough memory on the machine. Maybe it has been used up by another application. Maybe it has been used up by your application. Maybe your 32 bit application have used up its memory address space of 2 Gigabyte.
To diagnose this error, then use Process Explorer to capture a Fulldump of the application that uses too much memory. Then try using Visual Studio or WinDbg to investigate the memory dumpfile.
To remove NLog from the radar, then you can upgrade to NLog 4.4.6 (or newer). It will reduce memory allocations with 70 pct. from older versions (When using FileTarget)
If running NLog 4.4.6 (or newer) then you can optimize NLog even further by not using <targets async="true"> but instead use this default-wrapper:
<targets>
<default-wrapper xsi:type="AsyncWrapper" timeToSleepBetweenBatches="0" />
<target .... />
<target .... />
</targets>
See also https://github.com/NLog/NLog/wiki/Performance

.Net Windows Service Crashes with MSVCR120_CLR0400.dll exception

We have a windows service in production server which is Windows Server 2008 r2 standard and installed .net framework version 4.5.2 in it.
Service stopped twice in last one week suddenly with below event viewer sourced exception :
Event Id :1026 , .net runtime exception:
Application: XXX.Application.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at System.Buffer.__Memcpy(Byte*, Byte*, Int32)
at System.Buffer.__Memcpy(Byte*, Byte*, Int32)
at System.Buffer._Memcpy(Byte*, Byte*, Int32)
at System.Buffer.Memcpy(Byte*, Byte*, Int32)
at System.String.ToCharArray()
at FluentValidation.Internal.Extensions+<>c__DisplayClassd`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable`1[[System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<CoerceToNonGeneric>b__c(System.Object)
at FluentValidation.Validators.PropertyValidatorContext.get_PropertyValue()
at FluentValidation.Validators.AbstractComparisonValidator.IsValid(FluentValidation.Validators.PropertyValidatorContext)
at FluentValidation.Validators.PropertyValidator.Validate(FluentValidation.Validators.PropertyValidatorContext)
at FluentValidation.Internal.PropertyRule+<Validate>d__8.MoveNext()
at System.Linq.Enumerable+<SelectManyIterator>d__14`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]].MoveNext()
at System.Collections.Generic.List`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
at System.Linq.Enumerable.ToList[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
at FluentValidation.AbstractValidator`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Validate(FluentValidation.ValidationContext`1<System.__Canon>)
Event ID :1000
Faulting application name: XX.Application.exe, version: 2.1.0.5017, time stamp: 0x59b1865e
Faulting module name: MSVCR120_CLR0400.dll, version: 12.0.51209.34209, time stamp: 0x5348a2f4
Exception code: 0xc0000005
Fault offset: 0x0000000000001630
Faulting process id: 0x12a8
Faulting application start time: 0x01d3307a3a9dca66
Faulting application path: XX.Application.exe
Faulting module path: C:\Windows\system32\MSVCR120_CLR0400.dll
Report Id: 5ea7c0b6-a0f0-11e7-8d71-0050568c317d
I've googled for a week but couldn't get any answer.
Would you please help me about what could be the problem with our windows service or what should I do to find problem ?
Thanks.
After I posted this question, we realized that we had compiled code with x86 run platform from teamcity before we publish code to server. After that publish, this problem occurred.But we should have done this publish with x64 platform because our server is 64 bit.
After realizing that, we get publish packages again from Visual Studio with Release Mode and Mixed Platform setted.
For two weeks, problem never happened again ,so I wanted to share that solution.
In conclusion, It was because our publish package's run platform confusion. If you ever come up to that problem may be you should check your publish packages run platform.
Your code probably deals incorrectly with Enumerables. To find the root cause I suggest subscribing to unhanded exception and write as much details as you can to logs:
public static void Start() {
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);
running = true;
ThreadStart ts = new ThreadStart(ServiceThreadBody);
thread = new Thread(ts);
thread.Name = "ServiceThread";
thread.Priority = ThreadPriority.BelowNormal;
thread.Start();
}

App exe crashing at startup. Faulting module path c:\windows\syswow64\kernalbase.dll

Whenever I try to launch my app on a machine that isnt mine it crashes at start up. I am at a loss and have done a ton of searching with no resolution. There is no real error I just get the standard windows 7 not responding. All machines are win7Pro 64 with .net4. I am seeing the event viewer logs below.
Event id 1000:
Faulting application name: MarketingRequests.exe, version: 1.0.0.0, time stamp: 0x5033e787
Faulting module name: KERNELBASE.dll, version: 6.1.7601.17651, time stamp: 0x4a5bdbdf
Exception code: 0xe0434352
Fault offset: 0x0000b9bc
Faulting process id: 0x1ecc
Faulting application start time: 0x01cd7fe56831cfd9
Faulting application path: C\Intranet\MarketingRequests.exe
Faulting module path: C:\Windows\syswow64\KERNELBASE.dll
Report Id: a78399b1-ebd8-11e1-9474-f04da20e6eaf
I am also seeing event ID 1026, .net runtime:
Log Name: Application
Source: .NET Runtime
Date: 8/21/2012 9:08:53 PM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: CORRIE-Z.msing.local
Description:
Application: ExpenseReport.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
Stack:
at System.Data.Linq.SqlClient.SqlProvider.Execute(System.Linq.Expressions.Expression, QueryInfo, System.Data.Linq.SqlClient.IObjectReaderFactory, System.Object[], System.Object[], System.Data.Linq.SqlClient.ICompiledSubQuery[], System.Object)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(System.Linq.Expressions.Expression, QueryInfo[], System.Data.Linq.SqlClient.IObjectReaderFactory, System.Object[], System.Data.Linq.SqlClient.ICompiledSubQuery[])
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(System.Linq.Expressions.Expression)
at System.Data.Linq.DataQuery1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].System.Linq.IQueryProvider.Execute[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.Expressions.Expression)
at System.Linq.Queryable.First[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.IQueryable1)
at ExpenseReport.frmMain.refreshEmpInfo()
at ExpenseReport.frmMain..ctor()
at ExpenseReport.Program.Main()
Event Xml:
1026
2
0
0x80000000000000
26474
Application
CORRIE-Z.msing.local
Application: ExpenseReport.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
Stack:
at System.Data.Linq.SqlClient.SqlProvider.Execute(System.Linq.Expressions.Expression, QueryInfo, System.Data.Linq.SqlClient.IObjectReaderFactory, System.Object[], System.Object[], System.Data.Linq.SqlClient.ICompiledSubQuery[], System.Object)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(System.Linq.Expressions.Expression, QueryInfo[], System.Data.Linq.SqlClient.IObjectReaderFactory, System.Object[], System.Data.Linq.SqlClient.ICompiledSubQuery[])
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(System.Linq.Expressions.Expression)
at System.Data.Linq.DataQuery1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].System.Linq.IQueryProvider.Execute[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.Expressions.Expression)
at System.Linq.Queryable.First[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.IQueryable1<System.__Canon>)
at ExpenseReport.frmMain.refreshEmpInfo()
at ExpenseReport.frmMain..ctor()
at ExpenseReport.Program.Main()
It looks like frmMain.refreshEmpInfo contains a LINQ query that retrieves a record from the database, and the LINQ query calls First() to get the first record. Is it possible that no records are being returned, which would cause First() to throw an InvalidOperationException?
(It might be helpful if you posted the code in frmMain.refreshEmpInfo. You might also want to wrap that code in a try...catch block and display the exception details in a message box.)

How to get SMO application working on another Machine

I wrote an application using SMO it installs and runs fine on my dev pc, even installing in another location and running it,
but when i move it to another machine it gives the following error
Log Name: Application
Source: .NET Runtime
Date: 4/10/2012 12:03:56 PM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: ip-0A3AF6C2
Description:
Application: DataExport.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: Microsoft.SqlServer.Management.Common.ConnectionFailureException
Stack:
at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
at DataExport.Data.SqlDataService.GetTableNames(System.String)
at DataExport.Adapter.DataExportAdapter.GetTableNames(System.String)
at DataExport.DataExportForm.SetInitialEditDisplay(DataExport.Adapter.IDataExportAdapter)
at DataExport.DataExportForm..ctor(DataExport.Adapter.IDataExportAdapter)
at DataExport.Program.Main()
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="2012-04-10T11:03:56.000Z" />
<EventRecordID>72945</EventRecordID>
<Channel>Application</Channel>
<Computer>ip-0A3AF6C2</Computer>
<Security />
</System>
<EventData>
<Data>Application: DataExport.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: Microsoft.SqlServer.Management.Common.ConnectionFailureException
Stack:
at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
at DataExport.Data.SqlDataService.GetTableNames(System.String)
at DataExport.Adapter.DataExportAdapter.GetTableNames(System.String)
at DataExport.DataExportForm.SetInitialEditDisplay(DataExport.Adapter.IDataExportAdapter)
at DataExport.DataExportForm..ctor(DataExport.Adapter.IDataExportAdapter)
at DataExport.Program.Main()
</Data>
</EventData>
</Event>
I have no idea how to solve this, the SMO dlls are included in the package
Is there any possiblility that the older version of smo (pre 10) is overriding the dlls included?
OK the solution is that SMO 10 is only for Server 2008, it will not work with 2005 SQL Express
So the answer was to lower the version to 9.0

Categories