WCF error: extension could not be loaded
Asked Answered
D

2

9

I defined a class in my project which overrides IDispatchMessageInspector and I added the configuration related but it's doesn't work

System.Configuration.ConfigurationErrorsException: The type 'InMotionGIT_NT.Address.Service, CustomHeaders, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' registered for extension 'customHeaders' could not be loaded. (C:\Users\jmachado\Documents\Visual Studio 2010\Projects\InMotionGIT_NT\Address Service\InMotionGIT_NT.Address.Service\bin\Debug\InMotionGIT_NT.Address.Service.dll.config line 67)

this is how i called my custom extension

<endpointBehaviors>
    <behavior name="jsonBehavior">
        <enableWebScript/>
        <customHeaders/>
        <!--<webHttp/>-->
    </behavior>
</endpointBehaviors>    

this is how i defined my custom extension

<behaviorExtensions>
    <add name="customHeaders" type="InMotionGIT_NT.Address.Service, CustomHeaders, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>

Here's the class that I defined, that's inside of my project

[AttributeUsage(AttributeTargets.Class)]
public class CustomHeaders : IDispatchMessageInspector
{
    public object AfterReceiveRequest(ref Message request, ClientChannel channel, InstanceContext instanceContext)
    {
        if ((WebOperationContext.Current.IncomingRequest.Method == "GET"))
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "POST");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");
        }
        return null;
    }

    public void BeforeSendReply(ref Message reply, object correlationState)
    {
    }
}

Do I miss something in the configuration?

Disenthrone answered 28/5, 2012 at 15:50 Comment(0)
L
25

Change your type definition. First, specify the full type name (namespace + class name). After a comma, place the name of the DLL holding your type. And then the rest for a fully qualified type name. Like this:

<behaviorExtensions>
    <add name="customHeaders" type="InMotionGIT_NT.Address.Service.CustomHeaders, <DLLName> , Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
Laughingstock answered 28/5, 2012 at 17:53 Comment(1)
Note that in many cases (for example, private types), you don't need the fully qualified name, i.e., just doing My.Namespace.MyType, MyDll might be all you need.Lillith
C
0

Be sure that version is the same as the dll version. In my case i was referencing the same asssemlby that these classes are part of. But i had changed the version of the assembly in the AssemlbyInfo.cs file which did not matched with the version here in App.config file.

Cusped answered 3/11, 2016 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.