WCF error: extension could not be loaded

I defined a class in my project that overrides IDispatchMessageInspector , and I added a related configuration, but it does not work.

System.Configuration.ConfigurationErrorsException: Type "InMotionGIT_NT.Address.Service, CustomHeaders, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null" registered for the extension "customHeaders" cannot 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 what 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 is the class that I defined that inside 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) { } } 

Am I missing something in the configuration?

+7
source share
2 answers

Change the definition of your type. First enter the fully qualified type name (namespace + class name). After the comma, specify the name of the DLL containing your type. And then the rest for the full 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> 
+19
source

Make sure the version matches the version of the dll. In my case, I referred to the same asssemlby that these classes are part of. But I changed the version of the assembly in the AssemlbyInfo.cs file, which did not match the version here in the App.config file.

0
source

Source: https://habr.com/ru/post/916855/


All Articles