System servicemodel error

Technical articles, content and resources for IT Professionals working in Microsoft technologies

Table of Contents

  • Introduction
  • The FaultContract
    • Server side code:
    • Client side code:
  • Disabling the error


Introduction

Years ago, I personally met the famous error «System.ServiceModel.FaultException’1 was not handle by user code» in one of my WCF project. Since that tile I get a lot of great comment on my blog on that same issue still today. In order to bring to that topic
a better visibility, I decided to write and update that article here on this wiki.

Managing a correct error handling process in an application is a nightmare if you want to do it properly and I would say that it is not always the best exciting part, but it is absolutly needed to prevent as much as possible unhandle situation. In a normal
application you simply place the code inside try-catch block with the exception type, and there are handle as normal .net exception object that you can bubble up.

With WCF service I have discover around different reading that it is a bit different, simply because WCF need to guaranty interoperability with any client application in order that they are able to catch error returned.

For that WCF need to convert the “normal .NEt exception” into a SOAP message exception that will be understandable from client application.

The FaultContract

To achive this you need to specify a FaultContract attrribute in your service either declaratively or imperatively way. For my case I have done it with declarative.

 You specify the declarative FaultContrat as follow for your service method:

OperationContract]

 [FaultContract (typeof(MyError))]

 Boolean myMethod();

MyError is here a custom type which define an error message

After having configured the service FaultContractAttribute, next you need to raise the exception from your server side service method code as follow :

Server side code:

catch
(Exception exc)

 {

   MyError ErrLog =
new
Maillefer.Nomos.Types.Common.MyError (“This
is
an error”,”Critical”);

   FaultException<MyError> fe =
new
FaultException<MyError >(ErrLog,
new
FaultReason(ErrLog.Message));

   throw
fe;

 }

Client side code:

From the client application side you simply need to catch the FaultException error type as you normally do and retrive the message return by the Servcie SOAP message as follow:

catch
(FaultException <MyError> MyError)

 {

   string
msg = Error.Detail.Message;

   MessageBox.Show (msg);

   wcfclient.Close();

 }

You then receive the error message send from your server, inside your client application.. Hmmm this is what I was expecting but it was not behaving as expected. I spend days to cross check my code and verify impementation to get the exception
correctly thrown but when runnig my application my service was stoping at the time it was throwing the exception (throw fe). The error return from that execution was something strange like :

System.ServiceModel.FaultException`1 was unhandled by user code

After a lot of research I find out the solution on a post mentionning that it was due to some setting of
debugging scenario of my VS environement, which make my code execution stop at each exception with not really logic message wich was giving a lot of confusion.

Disabling the error

To remove this behaviour it was advise to uncheck the 2 following options from theVisual Studio Editor Tools->Option menu of IDE:

So simple thing which could save your weeks.

I am using windows environment and my goal is to display the Windows user name of the user that accessed my silverlight web page.
On doing some research I found that the only way to do this would be to call a web service method that can return the user’s identify.

So, I created a WCF Service and exposed an operation, adding service reference and all but when client tries to call it I get an exception.

Looks like my web service method doesn’t even get called. I placed a break point there and it never hit.

Exception:

System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI

‘http://MyComputer/SilverlightApplication1.Web/Service/DemoService.svc’. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need
to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute
attribute. Please see the
inner exception for more details. —>

System.Security.SecurityException —>
System.Security.SecurityException: Security error at
System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult
asyncResult) at
System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState) atSystem.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
   — End of inner exception stack trace —at
System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object
state)at
System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at

System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)

My web.config file is:

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<identity impersonate="false" />
<authentication mode="Windows" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior></serviceBehaviors></behaviors>

<bindings>
<basicHttpBinding>
<binding name="winAuthBasicHttpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding></bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="SilverlightApplication1.Web.Service.DemoService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="winAuthBasicHttpBinding" contract="SilverlightApplication1.Web.Service.DemoService" />
</service>
</services>
</system.serviceModel>
</configuration

And my clientapp.config file is:

<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_DemoService" maxBufferSize="2147483647"maxReceivedMessageSize="2147483647">
<security mode="TransportCredentialOnly">
</security>
</binding>

</basicHttpBinding>

</bindings>

<client>

<endpoint address="http://MyComputer/SilverlightApplication1.Web/Service/DemoService.svc"binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DemoService"contract="ServiceReference1.DemoService" name="BasicHttpBinding_DemoService" />

</client>

</system.serviceModel>

</configuration>

My clientaccesspolicy.xml file is placed under the SilverlightApplication.Web folder in my VS2010 project directory. I am hosting from VS itself not
IIS.

<?xml version="1.0" encoding="utf-8"?>

<access-policy>

<cross-domain-access>

<policy><allow-from http-request-headers="SOAPAction">

<domain uri="http://*"/>

<domain uri="https://*" />

<domain uri="*" />

</allow-from>

<grant-to><resource path="/" include-subpaths="true"/>

</grant-to></policy></cross-domain-access>

</access-policy>

Any help would be appreciated.

Thanks

@HASSEN-MEDDEB-ATOS commented on Thu Jan 30 2020

Hello again,

i have migrated my project from .NET Framework to .NET core. i have changed this line from

  sp.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
to

 sp.ServiceConfiguration.CurrentServiceEndpoint.EndpointBehaviors.Add(new ProxyTypesBehavior());
because we used System.ServiceModel.Primitives 

but it return Exception: Could not load type ‘System.ServiceModel.Description.MetadataConversionError’ from assembly ‘System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

Thanks for all helps

Cordially


@maryamariyan commented on Thu Jan 30 2020

cc: @dotnet/dotnet-wcf


@StephenBonikowsky commented on Thu Jan 30 2020

@HASSEN-MEDDEB-ATOS The types you mentioned belong to WCF. (https://github.com/dotnet/wcf)

Not all of WCF from the full framework is available in WCF Core. We are still adding support for many features but some are not yet available and others we will not be able to support. Server side APIs will not be supported in WCF Core only Client side APIs.

System.ServiceModel.Description.MetadataConversionError is not currently supported. You can check any API in the https://apisof.net/ tool to see where it is supported.

@mconnew Is this API related to server side stuff or could it be added to the WCF Core public surface area. Looks like it was at least partially implemented in WCF Core although I don’t see any references to it.


@HASSEN-MEDDEB-ATOS commented on Fri Jan 31 2020

Helle @StephenBonikowsky ,

Thanks for your answer.
I can’t undestrand somthing, System.ServiceModel is deprecated in both .NET Standard and .NET Core. I have added the new package «System.ServiceModel.Primitives» i can see that System.ServiceModel has been added in the reference with version «4.7.0». the question, why i get System.ServiceModel, Version=4.0.0.0 not load ? even so i have installed the version 4.7.0

Cordially


@StephenBonikowsky commented on Fri Jan 31 2020

On full framework System.ServiceModel.dll contains most of the WCF implementation.

WCF Core works differently, all the implementation code lives in the System.Private.ServiceModel package but that package cannot be referenced directly. Instead we have 5 Façade packages in which the ref assembly has a list of publicly accessible APIs and the lib assembly type-forwards to the implementation in System.Private.ServiceModel.

Because the full framework supports netstandard2.0 as does WCF Core, we have included in our System.Primitives.ServiceModel package a Façade assembly called System.ServiceModel.dll for the scenario where you build your application on the full framework targeting netstandard2.0 and then run it on WCF Core. In that case the System.ServiceModel.dll Façade will type-forward to the WCF Core implementation in System.Private.ServiceModel.dll. It only knows about types that are supported on both full framework and core as per netstandard2.0.

So back to your error. You are trying to load a type that is not supported in WCF Core and the System.ServiceModel Façade knows nothing about it.

Since this is a WCF issue, I amgoing to move it to the WCF Repo.

In this post, we will learn how to solve “Could not load type system.servicemodel.activation.httpmodule from assembly system.servicemodel” that you may face After Installing a .NET Framework 4.0.

  1. 1
    Could not load type system.servicemodel.activation.httpmodule

    1. 1.1
      Solution

      1. 1.1.1
        1) Updating Applicationhost.config

      2. 1.1.2
        2) Perform ASP.NET IIS Registration.

      3. 1.1.3
        3) Turn on the Named Pipe Activation feature

      4. 1.1.4
        4) Remove ServiceModel 3.0 from IIS


This issue occurs because the Applicationhost.config file for Windows Process Activation Service (WAS) has some tags that are not compatible with the .NET Framework 4.0.

“Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′”

Could not load type system.servicemodel.activation.httpmodule
Could not load type ‘system.servicemodel.activation.httpmodule’ from assembly ‘system.servicemodel

Solution

To solve “Could not load type system.servicemodel.activation.httpmodule from assembly ‘system.servicemodel, you have four different options as the following:

  1. Updating Applicationhost.config.
  2. Perform ASP.NET IIS Registration.
  3. Turn on the Named Pipe Activation feature.
  4. Remove ServiceModel 3.0 from IIS

1) Updating Applicationhost.config

Steps

  • Go to Applicationhost.config file that located in %windir%system32inetsrvconfig
  • Open Applicationhost.config for edit and search for “ServiceModel”
edit Applicationhost.config
system.servicemodel.activation.httpmodule
  • Replace the following Tag
<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule,
 System.ServiceModel, Version=3.0.0.0, Culture=neutral,
 PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
  • With the belowtag
<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule,
 System.ServiceModel, Version=3.0.0.0, Culture=neutral,
 PublicKeyToken=b77a5c561934e089" 
preCondition="managedHandler,runtimeVersionv2.0" />
  • Save the file.
  • Go back to browse your site that should be now working properly.

2) Perform ASP.NET IIS Registration.

If the above solution doesn’t work, you will need to perform ASP.NET IIS Registration using CMD as the following:

Steps
  • Go to Start Menu > Run > cmd.
  • Type the following command
cd  %windir%Microsoft.NETFrameworkv4.0.30319 -->> aspnet_regiis.exe /iru
error-cmdaspnet_reg

3) Turn on the Named Pipe Activation feature

In windows Server 2016 / 2012, you should Turn on the Named Pipe Activation feature as the following:

Steps
  • Open Server Manager > Manage > Add Role and Features.
Add role and feature in Windows Server
  • Follow the wizard, and at Features > click on .Net framework 4.5 features > WCF Services > Check “Named Pipe Activation”
Turn on the Named Pipe Activation feature

For windows 10 and windows 8, you have to use control panel > Programs and Features > Turn on Windows Features on or off, check “Named Pipe Activation”

turn on Named Pipe Activation in windows 10

4) Remove ServiceModel 3.0 from IIS

If the above solution doesn’t work, make sure that the ServiceModel 3.0 in IIS Modules is removed by doing the following:

  • Open IIS > Click on Server Name > Modules.
remove service model 3 from iis
  • Search for ServiceModel 3.0 > Right Click and select Remove.
remove module from iis

Conclusion

After installing .NET Framework 4.0, you may get “Could not load type system.servicemodel.activation.httpmodule from assembly ‘System.ServiceModel”. so In this post, we have provided 3 solutions to fix this issue.

See Also
  • How to Encrypt Connection String in Web.config in ASP.NET.
  • SharePoint 2016: A strongly-named assembly is required
  • ASP.NET Core for Beginners

Introduction

I encountered an error when I was deploying my WebSocket server application which targeted .NET 4.5 to Windows Server 2012 plus IIS 8. It was an exception shown in browser whenever I tried to open a web page. The exception said:

"Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly
 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'"

When I was working on IIS 7.5, I heard about this problem and knew the cause: the default configuration in applicationHost.config (in C:WindowsSystem32inetsrvconfig) declared two conflicted modules
and two conflicted handlers:

<modules>
  <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, 
  System.ServiceModel, Version=3.0.0.0, Culture=neutral, 
  PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
  <add name="ServiceModel-4.0" type="System.ServiceModel.Activation.ServiceHttpModule, 
  System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, 
  PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler,runtimeVersionv4.0" />
</modules>
<handlers>
  <add name="svc-Integrated" path="*.svc" verb="*" 
  type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, 
  Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode" />
  <add name="svc-Integrated-4.0" path="*.svc" verb="*" 
  type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, 
  System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, 
  PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

As we know, applicationHost.config contains the root settings for all web sites and web applications on the server. Therefore, any web application would have all the four conflicted modules
and handlers loaded by default. “ServiceModel” and “svc-Integrated” were for .NET Activation 3.x while “ServiceModel-4.0
and “svc-Integrated-4.0” were for .NET Activation 4.x. Unfortunately, the 3.x items were declared before the 4.x items. That was why the exception occurred for a .NET 4.x web application!

Then how did such a situation happen? On Windows Server 2008, it could happen when you install .NET 3.x framework or IIS 7.5 with Activation features after .NET framework 4.x is installed. However, on Windows Server 2012, it always
happens when you install .NET framework 3.x with Activation features.

Microsoft officially announced the solution (http://support.microsoft.com/kb/2015129) for Windows Server 2008 plus IIS 7.5: manually running “aspnet_regiis.exe
/iru
” for .NET framework 4.x (in C:WindowsMicrosoft.NETFrameworkv4.0.30319 or C:WindowsMicrosoft.NETFramework64v4.0.30319). However, aspnet_regiis.exe is not allowed to run for IIS
8. I tried manually changing applicationHost.config. I also tried removing and adding features in a good order. But all these solutions did not work.

The final solution was to delete the 3.x module and handler from IIS manager. You could delete them at the application or site level if you want to keep them in applicationHost.config. But
I wanted to delete them from applicationHost.config. So I did the following steps:

  1. In IIS manager, click the machine name node.
  2. In “Features View”, double-click “Modules”.
  3. Find “ServiceModel” and remove it.

  4. Go back to the machine name node’s “Features View”, double-click “Handler Mappings”.
  5. Find “svc-Integrated” and remove it.

Now everything works well.

CodeProject

License

Written By

Architect

China China

Over 10-years experience in using Microsoft technologies.
At present, working as the architect of a clustered real-time data delivery and visualization system, responsible for the design of component architecture, product packaging and deployment, also targeting private cloud solutions for future.

LinkedIn

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

[Fix] — Error message after you install the .NET Framework 4.0 Could not load type System.ServiceModel.Activation.HttpModule

 

Scenario :

  • When I try to run a web application in visual studio the page could Not Load Type and the following error will occur

        ‘System.ServiceModel.Activation.HttpModule’.

  • And also If we try to run a service in the web application and receive a messages over the HTTP transport by receiving an error similar to the following:
Server Error in '/WCFApplication' Application 
Could not load type 
'System.ServiceModel.Activation.HttpModule' from assembly 
'System.ServiceModel, Version=3.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089'.
  • An unhandled exception occurs during the execution of the current Web request
  • And review the stack trace for more information about the error and check whether is originated in the code. 
Exception Details: System.TypeLoadException: 
Could not load type 
'System.ServiceModel.Activation.HttpModule' from assembly 
'System.ServiceModel, Version=3.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089'.

Error :

Error message after you install the .NET Framework 4.0: «Could not load type ‘System.ServiceModel.Activation.HttpModule‘»

Reason :

  • Generally, this issue will occur because the Applicationhost.config file for Windows Process Activation Service (WAS) was incompatible for .NET Framework 4.0
<add name="ServiceModel" 
type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, 
Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
preCondition="managedHandler" />

And define” precondition” like this way:

<add name="ServiceModel" 
type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, 
Version=3.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089" 
preCondition="managedHandler,runtimeVersionv2.0" />
Note :
  •  We can find the Applicationhost.config file using the following location:

        %windir%system32inetsrvconfig

Fix :

  • Here we can resolve this issue by run the following command:

aspnet_regiis.exe /iru

  • The Aspnet_regiis.exe file can be found in one of the following locations:
  • %windir%Microsoft.NETFrameworkv4.0.30319
  • %windir%Microsoft.NETFramework64v4.0.30319 (on a 64-bit computer)

Applies to :

  • Windows Workflow Foundation
  • Windows Communication Foundation
  • Microsoft .NET Framework 4

Related Tags :

  • Error message after you install the .NET Framework 4.0
  • Could not load type ‘System.ServiceModel.Activation.HttpModule’ 
  • asp.net — Could not load type ‘System.ServiceModel.Activation
  • Could not load type System.ServiceModel.Activation.HttpModule
  • Could not load type System.ServiceModel.Activation.HttpModule
  • Could not load type ‘System.ServiceModel.Activation.HttpModule’ from


Понравилась статья? Поделить с друзьями:
  • System service exception windows 10 причина как исправить
  • System service exception windows 10 как исправить через командную строку
  • System service exception ntfs sys windows 10 как исправить
  • System service exception dxgmms2 sys windows 10 как исправить
  • System service exception 0x0000003b windows 7 как исправить