使用非托管 DLL 托管 WCF 服务

发布于 2024-12-23 21:43:01 字数 3860 浏览 1 评论 0原文

我有一个托管 DLL,它在内部引用了几个非托管 DLL。此托管 DLL 作为对我的 WCF 服务项目的引用添加。但是,必须手动将非托管 DLL 复制到我的项目的构建输出路径。无法在 Visual Studio 中引用它们。

如果我尝试在 Visual Studio 中的 WCF 服务主机中运行我的服务 DLL,后者会毫无异常地崩溃并自动重新启动。如果我尝试在 IIS 中托管服务 DLL,则适用 Sampe。当我尝试在 IIS 中托管时,我能够捕获 WERReportMetadata 崩溃日志之一,并且 ProblemSignatures 说:

<ProblemSignatures>
    <EventType>CLR20r3</EventType>
    <Parameter0>webdev.webserver40.exe</Parameter0>
    <Parameter1>10.0.0.0</Parameter1>
    <Parameter2>4d5f345a</Parameter2>
    <Parameter3>GTAPIASM</Parameter3>
    <Parameter4>2.0.5.0</Parameter4>
    <Parameter5>4e9254a5</Parameter5>
    <Parameter6>166</Parameter6>
    <Parameter7>23</Parameter7>
    <Parameter8>System.AccessViolationException</Parameter8>
  </ProblemSignatures> 

这是什么意思以及我能做些什么?有关使用非托管 DLL 托管 WCF 的任何参考资料也将很有用。

编辑 1: 将非托管 DLL 复制到 %systemroot%\syswow64 允许我使用 Visual Studio WCF 服务主机托管我的服务。我从此处得到了提示。但是,这并不能阻止 WebDev.WebDServer40.exe 崩溃。

编辑 2 这是从事件查看器捕获的 .NET 运行时错误:

应用程序:WebDev.WebServer40.exe 框架版本:v4.0.30319 描述:由于未处理的异常,进程被终止。 异常信息:System.TypeInitializationException 堆栈:位于 System.RuntimeMethodHandle._InvokeConstructor(System.IRuntimeMethodInfo, System.Object[]、System.SignatureStruct ByRef、System.RuntimeType)位于 System.RuntimeMethodHandle.InvokeConstructor(System.IRuntimeMethodInfo, System.Object[]、System.SignatureStruct、System.RuntimeType)位于 System.Reflection.RuntimeConstructorInfo.Invoke(System.Reflection.BindingFlags, System.Reflection.Binder、System.Object[]、 系统.全球化.文化信息)位于 System.ServiceModel.Description.ServiceDescription.CreateImplementation(System.Type) 在 System.ServiceModel.Description.ServiceDescription.SetupSingleton(System.ServiceModel.Description.ServiceDescription, System.Object,布尔值)位于 System.ServiceModel.Description.ServiceDescription.GetService(System.Type) 在 System.ServiceModel.ServiceHost.CreateDescription(System.Collections.Generic.IDictionary`2 通过参考)在 System.ServiceModel.ServiceHostBase.InitializeDescription(System.ServiceModel.UriSchemeKeyedCollection) 在 System.ServiceModel.ServiceHost.InitializeDescription(System.Type, System.ServiceModel.UriSchemeKeyedCollection)位于 System.ServiceModel.ServiceHost..ctor(System.Type, System.Uri[]) at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(System.Type, System.Uri[]) 位于 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(System.String, System.Uri[]) 位于 System.ServiceModel.ServiceHostingEnvironment+HostingManager.CreateService(System.String) 在 System.ServiceModel.ServiceHostingEnvironment+HostingManager.ActivateService(System.String) 在 System.ServiceModel.ServiceHostingEnvironment+HostingManager.EnsureServiceAvailable(System.String) 在 System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(System.String) 在 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest() 在 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest() 在 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(System.Object) 在 System.Runtime.IOThreadScheduler+ScheduledOverlapped.IOCallback(UInt32, UInt32、System.Threading.NativeOverlapped*) 在 System.Runtime.Fx+IOCompletionThunk.UnhandledExceptionFrame(UInt32, UInt32、System.Threading.NativeOverlapped*) 在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32,System.Threading.NativeOverlapped *)

编辑 2:

结果我必须始终以管理员身份运行 Visual Studio。这消除了之前的错误。

谢谢。

I have a managed DLL that internally references a couple of unmanaged DLLs. This managed DLL is added as a reference to my WCF service project. However, the unmanaged DLLs have to be manually copied to the build output path of my project. They cannot be referenced within Visual Studio.

If I try to run my service DLL within the WCF Service Host in Visual Studio, latter crashes without any exceptions and automatically restarts. Sampe applies if I try to host service DLL in IIS. I was able to catch one of the WERReportMetadata crash logs when trying to host in IIS and the ProblemSignatures says:

<ProblemSignatures>
    <EventType>CLR20r3</EventType>
    <Parameter0>webdev.webserver40.exe</Parameter0>
    <Parameter1>10.0.0.0</Parameter1>
    <Parameter2>4d5f345a</Parameter2>
    <Parameter3>GTAPIASM</Parameter3>
    <Parameter4>2.0.5.0</Parameter4>
    <Parameter5>4e9254a5</Parameter5>
    <Parameter6>166</Parameter6>
    <Parameter7>23</Parameter7>
    <Parameter8>System.AccessViolationException</Parameter8>
  </ProblemSignatures> 

What does this mean and what can I do about it? Any reference material on WCF hosting with unmanaged DLLs will be useful too.

Edit 1: Copying the unmanaged DLLs to %systemroot%\syswow64 allows me to host my service using Visual Studio WCF Service Host. I got the tip from here. However, this does not stop WebDev.WebDServer40.exe from crashing.

Edit 2 This is .NET Runtime error captured from Event Viewer:

Application: WebDev.WebServer40.exe Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitializationException Stack: at
System.RuntimeMethodHandle._InvokeConstructor(System.IRuntimeMethodInfo,
System.Object[], System.SignatureStruct ByRef, System.RuntimeType) at
System.RuntimeMethodHandle.InvokeConstructor(System.IRuntimeMethodInfo,
System.Object[], System.SignatureStruct, System.RuntimeType) at
System.Reflection.RuntimeConstructorInfo.Invoke(System.Reflection.BindingFlags,
System.Reflection.Binder, System.Object[],
System.Globalization.CultureInfo) at
System.ServiceModel.Description.ServiceDescription.CreateImplementation(System.Type)
at
System.ServiceModel.Description.ServiceDescription.SetupSingleton(System.ServiceModel.Description.ServiceDescription,
System.Object, Boolean) at
System.ServiceModel.Description.ServiceDescription.GetService(System.Type)
at
System.ServiceModel.ServiceHost.CreateDescription(System.Collections.Generic.IDictionary`2
ByRef) at
System.ServiceModel.ServiceHostBase.InitializeDescription(System.ServiceModel.UriSchemeKeyedCollection)
at System.ServiceModel.ServiceHost.InitializeDescription(System.Type,
System.ServiceModel.UriSchemeKeyedCollection) at
System.ServiceModel.ServiceHost..ctor(System.Type, System.Uri[]) at
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(System.Type,
System.Uri[]) at
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(System.String,
System.Uri[]) at
System.ServiceModel.ServiceHostingEnvironment+HostingManager.CreateService(System.String)
at
System.ServiceModel.ServiceHostingEnvironment+HostingManager.ActivateService(System.String)
at
System.ServiceModel.ServiceHostingEnvironment+HostingManager.EnsureServiceAvailable(System.String)
at
System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(System.String)
at
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(System.Object)
at
System.Runtime.IOThreadScheduler+ScheduledOverlapped.IOCallback(UInt32,
UInt32, System.Threading.NativeOverlapped*) at
System.Runtime.Fx+IOCompletionThunk.UnhandledExceptionFrame(UInt32,
UInt32, System.Threading.NativeOverlapped*) at
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32,
UInt32, System.Threading.NativeOverlapped*)

Edit 2:

Turns out I have to run Visual Studio as admin at all times. This eliminates the previous error.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若相惜即相离 2024-12-30 21:43:01

我需要将非托管 DLL 添加到 %systemroot%\syswow64。完成此操作后,可以在 Visual Studio 中的 WCF 服务主机以及 ASP 开发服务器中运行我的服务。

I needed to add unmanaged DLLs to %systemroot%\syswow64. Did this and can run my service in WCF Service Host in Visual Studio as well as ASP Development server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文