gpt4 book ai didi

c# - ServiceHost的自定义Factory无法从GAC加载

转载 作者:太空宇宙 更新时间:2023-11-03 15:16:01 27 4
gpt4 key购买 nike

我在 IIS 中托管了一个 WCF 服务,该服务运行良好。实际上它按顺序使用以下 Global.asax 和 OrderService.svc 文件。

<%@ Application Codebehind="Global.asax.cs" Inherits="MyCompany.MyOrderServices.Global" Language="C#" %>

<%@ ServiceHost Language="C#" Debug="true" Service="MyCompany.ServiceLibrary.OrderServiceImpl" Factory="MyCompany.ServiceLibrary.GenericServiceHostFactoryImpl, MyCompany.ServiceLibrary"%>

我正在尝试制作一个\bin\'less WCF 服务并将其托管在 IIS 中。我将所有必要的程序集放入 GAC。当我向服务发出请求时,出现以下错误:

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load the assembly 'MyCompany.MyOrderServices'. Make sure that it is compiled before accessing the page.

Source File: /global.asax Line: 1

好吧,我通过如下更改 Global.asax 文件修复了这个错误:

<%@ Application Codebehind="Global.asax.cs" Inherits="MyCompany.MyOrderServices.Global, MyCompany.MyOrderServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXX" Language="C#" %>

所以我明白了:我必须将简单的类型名称更改为类型的程序集限定名称。实际上,在我修复了 Global.asax 错误之后,我得到了以下错误。

Could not load file or assembly 'MyCompany.ServiceLibrary' or one of its dependencies. The system cannot find the file specified.

然后我启用了 Fusion 日志记录并获得了以下信息:

=== Pre-bind state information ===

LOG: DisplayName = MyCompany.ServiceLibrary

(Partial)

WRN: Partial binding information was supplied for an assembly:

WRN: Assembly Name: MyCompany.ServiceLibrary | Domain ID: 4

WRN: A partial bind occurs when only part of the assembly display name is provided.

WRN: This might result in the binder loading an incorrect assembly.

WRN: It is recommended to provide a fully specified textual identity for the assembly,

WRN: that consists of the simple name, version, culture, and public key token.

WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.

LOG: Appbase = file:///C:/OrderServicePublish/

LOG: Initial PrivatePath = C:\OrderServicePublish\bin

Calling assembly : (Unknown).

===

LOG: This bind starts in default load context.

LOG: Using application configuration file: C:\OrderServicePublish\web.config

LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config

LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.

LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/98694738/2a3c07d8/MyCompany.MyServiceLibrary.DLL.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/98694738/2a3c07d8/MyCompany.MyServiceLibrary/MyCompany.MyServiceLibrary.DLL.

LOG: Attempting download of new URL file:///C:/OrderServicePublish/bin/MyCompany.MyServiceLibrary.DLL.

LOG: Attempting download of new URL file:///C:/OrderServicePublish/bin/MyCompany.MyServiceLibrary/MyCompany.MyServiceLibrary.DLL.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/98694738/2a3c07d8/MyCompany.MyServiceLibrary.EXE.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/98694738/2a3c07d8/MyCompany.MyServiceLibrary/MyCompany.MyServiceLibrary.EXE.

LOG: Attempting download of new URL file:///C:/OrderServicePublish/bin/MyCompany.MyServiceLibrary.EXE.

LOG: Attempting download of new URL file:///C:/OrderServicePublish/bin/MyCompany.MyServiceLibrary/MyCompany.MyServiceLibrary.EXE.

显然省略了 GAC 文件夹。然后我更改了 .svc 文件,如下所示:

<%@ ServiceHost Language="C#" Debug="true" Service="MyCompany.ServiceLibrary.OrderServiceImpl, MyCompany.ServiceLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXX"   Factory="MyCompany.ServiceLibrary.GenericServiceHostFactoryImpl, MyCompany.ServiceLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXX"%>

...但是我遇到了同样的错误。 ServiceHost 指令有什么问题。为什么不能从 GAC 文件夹加载程序集?

(注意 1:顺便说一句;我检查了以下链接,建议将简单类型名称更改为程序集限定类型名称,但它对我不起作用。

1) https://social.msdn.microsoft.com/Forums/vstudio/en-US/3c61739c-b1fe-46bd-b8eb-8e9485f8891b/wcf-service-without-bin-folder?forum=wcf

2) http://answers.flyppdevportal.com/categories/sharepoint2010/sharepoint2010programming.aspx?ID=7b968dc5-4522-4896-8684-34064f0baaf5 )

最佳答案

哈!

我好像忘了编辑 Web.config:它还包含程序集名称。

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="CORSEnablingModule" type="MyCompany.ServiceLibrary.Cors.CORSEnablingModule, MyCompany.ServiceLibrary" />
</modules>
</system.webServer>

现在,我已将其更改为完全限定名称,一切正常。

还是谢谢你

关于c# - ServiceHost的自定义Factory无法从GAC加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39074706/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com