Why isn't my custom WCF behavior extension element type being found?

99封情书 提交于 2019-11-27 18:42:06

Per the workaround that Microsoft posted on the Connect issue I filed for this, it's a known issue and there won't be any solution for it, at least in the current release:

The reason for failing to add a new service item: When adding a new item and updating the configuration file, the system will try to load configuration file, so it will try to search and load the assembly of the cusom extension in this config file. Only in the cases that the assembly is GACed or is located in the same path as vs exe (Program Files\Microsoft Visual Studio 9.0\Common7\IDE), the system can find it. Otherwise, the error dialog will pop up and "add a new item" will fail.

I understand your pain points. Unfortunately we cannot take this change in current release. We will investigate it in later releases and try to provide a better solution then,such as providing a browse dialog to enable customers to specify the path, or better error message to indicate some work around solution, etc...

Can you try the work around in current stage: GAC your custom extension assembly or copy it to "Program Files\Microsoft Visual Studio 9.0\Common7\IDE"?

We will provide the readme to help other customers who may run into the same issue.

Unfortunately, it appears I'm out of luck on this one.

Developer

I just used

[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")] 

So I have new assembly build number every time.

But we have

   <add name="clientCredential" type="Client.ClientCredentialElement, Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />

where Version=1.0.0.0 THIS IS WRONG!!!

So you have 2 options

  1. Back to

    //[assembly: AssemblyVersion("1.0.*")] 
    [assembly: AssemblyVersion("1.0.0.0")]  Keep it manually.
    [assembly: AssemblyFileVersion("1.0.0.0")] 
    
  2. Every build manually replace Version=1.0.0.0 with a correct number.

As an FYI to anyone who stumbles across this these days a possible solution is to FULLY qualify your assembly in your app.config/web.config. EG if you had

<system.serviceModel>
    <extensions>
        <behaviorExtensions>
            <add name="clientCredential" type="Client.ClientCredentialElement, Client" />
        </behaviorExtensions>
    </extensions>

try - replacing the values as necassary

<system.serviceModel>
    <extensions>
        <behaviorExtensions>
            <add name="clientCredential" type="Client.ClientCredentialElement, Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
        </behaviorExtensions>
    </extensions>

this particular solution worked for me.

I tried this with a new project just to make sure it wasn't your specific project/config and had the exact same issue.

Using fusion logs, it appears that the system looks for the behavior extensions ONLY in the IDE directory (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE). Copying the assembly to this directory in a post-build step works, but is ugly.

Do you have a copy of Framework.dll with your custom behavior in the bin directory of your web project? If not that is probably the problem. Visual Studio is looking for the implementation of the behavior. Since it's listed in your config it doesn't think to look in the other projects; it expects to find the assembly in the bin.

Depending on how your project is setup, it may be able to run in debug without this assembly being put in the bin, although VS usually builds it and puts it there. But again, it depends on how things are setup.

Anyway, might just want to double check at that the assembly is available at design time.

Here's the list of steps worked for me:

  • Install dll into GAC, i.e. gacutil /i Bla.dll
  • Get FQN of dll, i.e. gacutil /l Bla
  • Copy resulting FQN into Web.config
  • Add new service in VS
  • Uninstall dll from GAC, i.e. gacutil /u Bla

All together only.

Putting the assembly in the GAC would probably help, but I appreciate this isn't the answer you're looking for. Not sure where else VS will look for assemblies apart from the GAC and the directory containing devenv.exe.

I solved this by commenting out the relevant sections in the web.config including the element that used the custom extension, the element and the element.

After that I was able to add a WCF service to the project, add the lines back into the web.config and publish the project.

if you are using framework 3.5 the Culture=neutral in small not Culture=Neutral in CAPITAL

I had the extension class within the same project (dll) as my service class and could not get it to work. Once I moved it to another project and referenced it from the service project it worked. Just in case anyone else runs into this issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!