简体   繁体   English

C# Windows 服务导入 C++ dll 崩溃,事件 ID:1000 clr.dll

[英]C# Windows Service Import C++ dll Crash with Event ID: 1000 clr.dll

I have a Windows service which imports a C++ dll.我有一个导入 C++ dll 的 Windows 服务。 If I do pressure test, this Windows service will directly crashed with Event ID: 1000 showed module clr.dll but didn't log any exception.如果我做压力测试,这个 Windows 服务将直接崩溃,事件 ID:1000 显示模块 clr.dll 但没有记录任何异常。 Event message as below:事件消息如下:

<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="2020-10-26T08:22:52.027599500Z" />
    <EventRecordID>5246</EventRecordID>
    <Channel>Application</Channel>
    <Computer>computer</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Server.exe</Data>
    <Data>5.1.0.1</Data>
    <Data>5f8d0a4f</Data>
    <Data>clr.dll</Data>
    <Data>4.7.3680.0</Data>
    <Data>5f233da8</Data>
    <Data>c0000409</Data>
    <Data>0056aa27</Data>
    <Data>1fc4</Data>
    <Data>01d6ab1690751cd9</Data>
    <Data>Server.exe</Data>
    <Data>C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll</Data>
    <Data>0772888d-b659-483c-b80b-d7b4de714636</Data>
    <Data>
    </Data>
    <Data>
    </Data>
  </EventData>
</Event>

I have tried some ways:我尝试了一些方法:

  1. Windows Update Windows更新
  2. My C# project app.config add我的 C# 项目 app.config 添加
    <configuration>
       <runtime>
          <legacyCorruptedStateExceptionsPolicy enabled="true" />
       </runtime>
    </configuration>

and the function which use C++ dll add以及使用C++ dll添加的函数

[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
  1. All code use C++ dll are all added try catch, but Windows service still crashed without log any exception.所有使用C++ dll的代码都添加了try catch,但是Windows服务仍然崩溃,没有记录任何异常。

Windows environment is Windows Server 2016 64bit. Windows 环境为 Windows Server 2016 64 位。 C++ dll is x86 thus I use x86 CPU - debug to build the project. C++ dll 是 x86,因此我使用 x86 CPU - debug 来构建项目。 I suspect the reason of crash caused by C++ dll but can't prove it.我怀疑是 C++ dll 导致崩溃的原因,但无法证明。

It looks like the simple solution is to attach the debugger to the service.看起来简单的解决方案是调试器附加到服务。 You'll need to start Visual Studio as Administrator probably, because the service likely runs under a non-interactive login.您可能需要以管理员身份启动 Visual Studio,因为该服务可能在非交互式登录下运行。

The "CorruptedState" not-solutions are a throwback to IsBadReadPtr , another unreliable and flaky method that Microsoft invented in the past. “CorruptedState”非解决方案是对IsBadReadPtr的回归,这是微软过去发明的另一种不可靠和不稳定的方法。 While debugging, the debugger is the better solution.在调试时,调试器是更好的解决方案。 Once released to customers, neither approach is guaranteed to catch the problem.一旦发布给客户,这两种方法都不能保证能解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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