简体   繁体   中英

.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(); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM