问题 无法加载为扩展名“[extensionHere]”注册的类型[nameHere]


我一直在fx3.5上使用WCF学习和构建JSONP Web服务。你可以阅读我的一些试验 .NET ASMX - 返回纯JSON? 我终于得到了一个样本运行,但现在我正在将它拖入我的应用程序中。

该服务的web.config:

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="JsonpServiceBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="RivWorks.Web.Service.CustomerService">
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="jsonpBinding"
                  behaviorConfiguration="JsonpServiceBehavior"
                  contract="RivWorks.Web.Service.ICustomerService" />
      </service>
      <service name="RivWorks.Web.Service.NegotiateService">
          <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="jsonpBinding"
                  behaviorConfiguration="JsonpServiceBehavior"
                  contract="RivWorks.Web.Service.INegotiateService" />
      </service>
    </services>
    <bindings>
      <customBinding>
        <binding name="jsonpBinding" >
          <jsonpMessageEncoding />
          <httpTransport manualAddressing="true"/>
        </binding>
      </customBinding>
    </bindings>    
    <extensions>
      <bindingElementExtensions>
        <add name="jsonpMessageEncoding"
             type="RivWorks.Web.Service.JSONP.JsonpBindingExtension
                 , RivWorks.Web.Service
                 , Version=1.0.0.0
                 , Culture=neutral
                 , PublicKeyToken=null"/>
      </bindingElementExtensions>
    </extensions>
  </system.serviceModel>

我收到以下错误,我已经尝试了一切我能想到的解决方法。在我的代码中发现了一些错别字(Sevice而不是Service)。我正在使用找到的示例代码 MSDN。这是错误:

Configuration Error Description:** An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The type 'RivWorks.Web.Service.JSONP.JsonpBindingExtension
                , RivWorks.Web.Service
                , Version=1.0.0.0
                , Culture=neutral
                , PublicKeyToken=null' registered for extension 'jsonpMessageEncoding' could not be loaded.

Source Error:

Line 58:  <customBinding>
Line 59:      <binding name="jsonpBinding">
Line 60:          <jsonpMessageEncoding />
Line 61:          <httpTransport manualAddressing="true" />
Line 62:      <binding>

Source File: C:\RivWorks\dev\services\web.config    Line: 60

Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

有没有人对我还能检查什么有任何想法?有一个名为RivWorks.Web.Service.dll的DLL,它正在构建并复制到网站的bin目录中。 Web.config服务正被复制到Web站点的Services目录中。我在网站的web.config中没有任何冲突。我检查了所有拼写问题。


7695
2017-12-17 23:16


起源

这绝对不是官方的答案,但我只想分享一些对这个确切问题的沮丧:在IIS中我有站点A,它承载应用程序A(App_A)。然后我在站点A下有一个托管应用程序B(App_B)的虚拟目录。 App_A正在实施类似于上面的自定义扩展。 App_B的web.config从App_A的web.config继承了这个自定义扩展。这引发了这里描述的确切错误。这完全是我没有正确配置它的错。我只是想与大家分享。不确定它是否值得回答。 - dyslexicanaboko


答案:


是构建输出中的DLL(RivWorks.Web.Service.dll)吗?

接下来,尝试(对于“jsonpMessageEncoding”扩展名):

type="RivWorks.Web.Service.JSONP.JsonpBindingExtension, RivWorks.Web.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

注意不同的间距 " , " 和回车。

在那之后,我会高音查看字符串。编写一个控制台exe,引用你需要的dll(RivWorks.Web.Service),并输出:

Console.WriteLine(
     typeof(RivWorks.Web.Service.JSONP.JsonpBindingExtension)
     .AssemblyQualifiedName);

这是xml中你想要的字符串,逐字。不要在此字符串中包含任何额外的空格。


15
2017-12-17 23:21



跑到控制台应用程序,字符串回来就像我一样。捕获它在字符串var中,检查它,复制它,粘贴到我的服务web.config中仍然是相同的错误。其他想法? - Keith Barrows
是的,DLL在构建输出中。我使用BeyondCompare从我的本地机器项目区域移动到我的localhost目录。此外,从那里它进入Dev服务器上的Dev目录(通过BeyondCompare)。我检查了每一步的方法,每次都可以看到最新版本。 - Keith Barrows
我尝试将这一切都放在一条线上,就像你展示的一样,并没有任何区别。 :( - Keith Barrows
此外,错误消息显示“无法加载”,对我来说,这意味着它可以找到它,只是不加载它。再次擦洗我的代码。我真的需要了解JsonpBehavior,JsonpBindingElement,JsonpBindingExtension和JsonpEncoderFactory类中的所有内容...... - Keith Barrows
+1这个简单的命令真的做到了这一点!!!!如果您使用的是.NET4,请确保在运行反射时使用完整的配置文件而不是客户端配置文件。对我来说,我有问题,直到我改变。 - random65537