可能重复:
The element ‘behavior’ has invalid child element ‘myFaultExtension’ in wcf app.config
我正在尝试实施Creating and Handling Faults in Silverlight。 (This项目在我的机器上运行。)
我收到Visual Studio警告:
元素'behavior'具有无效的子元素'betterErrorMessagesFaults'。
其他地方的其他答案说我应该忽略它,但我不能,因为我无法更新非.Web项目(包含所有xaml文件的项目)中的服务引用。当我尝试时,我收到此错误:
分析程序错误消息:无法加载为扩展名“betterErrorMessagesFaults”注册的类型“MyProject.Web.Services.BetterErrorMessagesFaultBehavior,MyProject.Web.Services,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null”。< / p>
这是Web.config的相关部分:
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="betterErrorMessagesFaults"
type="MyProject.Web.Services.BetterErrorMessagesFaultBehavior, MyProject.Web.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<services>
<service name="MyProject.Web.Services.Service2">
<endpoint address="" binding="customBinding"
bindingConfiguration="MyProject.Web.Services.Service2.customBinding0"
contract="MyProject.Web.Services.Service2"
behaviorConfiguration="BetterErrorMessagesFaultBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="BetterErrorMessagesFaultBehavior">
<betterErrorMessagesFaults/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="MyProject.Web.Services.Service2.customBinding0">
<binaryMessageEncoding>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxDepth="2147483647" maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
BetterErrorMessagesFaultBehavior
只是课程here on MSDN的复制粘贴;只更改名称(我也尝试使用默认名称),并且命名空间更改为MyProject.Web.Services
。
我也尝试过交换
<add name="betterErrorMessagesFaults"
type="MyProject.Web.Services.BetterErrorMessagesFaultBehavior, MyProject.Web.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
与
<add name="betterErrorMessagesFaults"
type="MyProject.Web.Services.BetterErrorMessagesFaultBehavior, MyProject.Web.Services"/>
但没有效果。我读到这对空间等非常敏感,但我看不出任何问题。我也查看了AssemblyInfo,版本是1.0.0.0,文化只是空白(“”),我不知道PublicKeyToken是什么,但我怀疑这不是问题......
所以我很难过,不知道下一步该去哪儿。
答案 0 :(得分:3)
可能迟到了一点点,但是您可以通过执行以下操作来验证您是否具有类型名称:
Console.WriteLine(typeof(BetterErrorMessagesFaultBehavior).AssemblyQualifiedName);
那应该包含PublicKeyToken部分供您比较......