在 mscorlib.dll 中发生 System.ExecutionEngineException'

Posted

技术标签:

【中文标题】在 mscorlib.dll 中发生 System.ExecutionEngineException\'【英文标题】:System.ExecutionEngineException' occurred in mscorlib.dll在 mscorlib.dll 中发生 System.ExecutionEngineException' 【发布时间】:2021-09-04 15:18:55 【问题描述】:

我正在尝试使用 C# 和服务结构在 .NET Framework 上运行一个简单的 Client Servier Communicaton 应用程序。对于服务间通信,我正在尝试使用 gRPC,并且我已将客户端和服务器作为集群上的单独服务.我正在使用可靠的服务 API 来覆盖功能并建立服务间通信。但是,当我运行代码时,出现此错误:-

Exception thrown: 'Grpc.Core.RpcException' in mscorlib.dll
Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in
 'C:\Users\Administrator\source\repos\TestGRPC\ClientService\bin\x64\Debug\ClientService.exe'.

Additional Information: The runtime has encountered a fatal error. The address of the error was at 0xeed5af27, on thread 0x578. The error code is 0x80131623.
This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code.
Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
An unhandled exception of type 'System.ExecutionEngineException' occurred in mscorlib.dll

我找出了导致此错误的原因:-

static Random mRand = new Random();
        protected override async Task RunAsync(CancellationToken cancellationToken)
        
            long iterations = 0;
            ServicePartitionResolver partitionResolver = new ServicePartitionResolver("localhost:19000");
            var partition = partitionResolver.ResolveAsync(new Uri("fabric:/TestGRPC/gRPCServer"),
                ServicePartitionKey.Singleton, new System.Threading.CancellationToken()).Result;
            var endpoint = partition.Endpoints.ElementAt(mRand.Next(0, partition.Endpoints.Count));

            var address = endpoint.Address.Substring(endpoint.Address.IndexOf("\"\":\"") + 4);
            address = address.Substring(0, address.IndexOf("\""));

            Channel channel = new Channel(address, ChannelCredentials.Insecure);
            var client = new AccountService.AccountServiceClient(channel);
            while (true)
            
                cancellationToken.ThrowIfCancellationRequested();
                EmployeeName empName = client.GetEmployeeName(new EmployeeNameRequest  EmpId = "1" );
                if (empName == null || string.IsNullOrWhiteSpace(empName.FirstName) || string.IsNullOrWhiteSpace(empName.LastName))
                
                    ServiceEventSource.Current.ServiceMessage(this.Context, "Emplyee Not found");
                    Console.WriteLine("Employee not found.");
                
                else
                
                    ServiceEventSource.Current.ServiceMessage(this.Context, "Emplyee Name: 0 1", empName.FirstName, empName.LastName);
                    Console.WriteLine($"The employee name is empName.FirstName empName.LastName.");
                
                ServiceEventSource.Current.ServiceMessage(this.Context, "Working-0", ++iterations);

                await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
            
        

是线

EmployeeName empName = client.GetEmployeeName(new EmployeeNameRequest  EmpId = "1" );

我怀疑域名无法正确解析,或者我不知道如何生成正确的域名地址。警告消息中也指出了这一点。服务器似乎在集群上运行良好。 集群上显示的警告消息和堆栈跟踪是:-

'RunAsync' reported Warning for property 'RunAsyncUnhandledException'.
Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="DNS resolution failed for service: MININT-H7Q1KHO:50001", DebugException="Grpc.Core.Internal.CoreErrorDetailException: "created":"@1624221009.546000000","description":"Resolver transient failure","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc","file_line":1361,"referenced_errors":["created":"@1624221009.546000000","description":"DNS resolution failed for service: MININT-H7Q1KHO:50001","file":"..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\dns_resolver_ares.cc","file_line":362,"grpc_status":14,"referenced_errors":["created":"@1624221009.545000000","description":"C-ares status is not ARES_SUCCESS qtype=A name=MININT-H7Q1KHO is_balancer=0: Domain name not found","file":"..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\grpc_ares_wrapper.cc","file_line":724,"referenced_errors":["created":"@1624221009.545000000","description":"C-ares status is not ARES_SUCCESS qtype=AAAA name=MININT-H7Q1KHO is_balancer=0: Domain name not found","file":"..\..\..\src\core\ext\filters\client_channel\resolver\dns\c_ares\grpc_ares_wrapper.cc","file_line":724]]]")
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg) in /var/local/git/grpc/src/csharp/Grpc.Core/Internal/AsyncCall.cs:line 78
   at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request) in /var/local/git/grpc/src/csharp/Grpc.Core/DefaultCallInvoker.cs:line 46
   at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx) in /var/local/git/grpc/src/csharp/Grpc.Core.Api/Interceptors/InterceptingCallInvoker.cs:line 51
   at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation) in /var/local/git/grpc/src/csharp/Grpc.Core.Api/ClientBase.cs:line 174
   at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request) in /var/local/git/grpc/src/csharp/Grpc.Core.Api/Interceptors/InterceptingCallInvoker.cs:line 48
   at AccountService.AccountServiceClient.GetEmployeeName(EmployeeNameRequest request, CallOptions options) in C:\Users\Administrator\source\repos\TestGRPC\ClientService\AccountGrpc.cs:line 100
   at AccountService.AccountServiceClient.GetEmployeeName(EmployeeNameRequest request, Metadata headers, Nullable`1 deadline, CancellationToken cancellationToken) in C:\Users\Administrator\source\repos\TestGRPC\ClientService\AccountGrpc.cs:line 96
   at ClientService.ClientService.<RunAsync>d__3.MoveNext() in C:\Users\Administrator\source\repos\TestGRPC\ClientService\ClientService.cs:line 56
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.ServiceFabric.Services.Runtime.StatelessServiceInstanceAdapter.<ExecuteRunAsync>d__18.MoveNext()

我已经被困在这个问题上很长时间了。我对 SF 有点陌生,不知道如何解决这个问题。任何帮助将不胜感激。

【问题讨论】:

异常为DNS resolution failed for service: MININT-H7Q1KHO:50001,因此,您可能需要在网络侧检查。 感谢您的信息,但服务器实例运行正常。您是否希望我检查任何具体的事情,因为我可以看到服务在给定的地址启动并运行? @aybe 如上所述,显然问题是 gRPC 无法寻址。您可以尝试的事情:1. 使用“grpcurl”github.com/fullstorydev/grpcurl 命令行客户端来测试服务是否可以手动访问 2. 尝试设置 GRPC_DNS_RESOLVER=native 以使用不同的解析器(请参阅github.com/grpc/grpc/blob/master/doc/environment_variables.md) 【参考方案1】:

我发现 gRPC 库本身存在一些问题。最新版本的库在服务结构群集上的 DNS 解析期间显示异常行为。但是,这个问题主要只发生在 Windows 上。

一种解决方法是在代码早期的某处设置环境变量 "GRPC_DNS_RESOLVER=native"。但是,这只是一个临时修复,不建议用于生产代码。

可以在此处找到有关相同的讨论线程:https://github.com/grpc/grpc/issues/18411

【讨论】:

以上是关于在 mscorlib.dll 中发生 System.ExecutionEngineException'的主要内容,如果未能解决你的问题,请参考以下文章

在 WPF C# 中保存图像时出现错误 System.UnauthorizedAccessException 在 mscorlib.dll 中发生

如何修复mscorlib.dll中发生的''System.AggregateException'“

“System.OutOfMemoryException”类型的异常在 mscorlib.dll 中发生,但未在用户代码中进行处理

EF异常:“System.InvalidOperationException”类型的未经处理的异常在 mscorlib.dll 中发生

“System.IO.FileNotFoundException”类型的未经处理的异常在 mscorlib.dll 中发生

mscorlib.dll 中出现“System.ServiceModel.CommunicationException”类型的未处理异常