[c#] WCF, Service attribute value in the ServiceHost directive could not be found

I'm trying to host my service with IIS 6 but I keep get this exception.

    Server Error in '/WebServices' Application.
--------------------------------------------------------------------------------

The type 'QS.DialogManager.Communication.IISHost.RecipientService', provided as the Service attribute value in the ServiceHost directive could not be found. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The type 'QS.DialogManager.Communication.IISHost.RecipientService', provided as the Service attribute value in the ServiceHost directive could not be found.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[InvalidOperationException: The type 'QS.DialogManager.Communication.IISHost.RecipientService', provided as the Service attribute value in the ServiceHost directive could not be found.]
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +6714599
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +604
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +46
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +654

[ServiceActivationException: The service '/WebServices/dm/RecipientService.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'QS.DialogManager.Communication.IISHost.RecipientService', provided as the Service attribute value in the ServiceHost directive could not be found..]
   System.ServiceModel.AsyncResult.End(IAsyncResult result) +15626880
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +15546921
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +265
   System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +227
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082 

I have absolutely no clue except that it seems like it can't find my assemblies. The code should be correctly compiled with public classes.

Here is my .svc file:

<%@ ServiceHost Language="C#" Debug="true" Service="QS.DialogManager.Communication.IISHost.RecipientService" CodeBehind="RecipientService.svc.cs" %>

I have tried to create a very very simple service that contains just nothin too see if this would work but still the same old error shows up.

The type 'IISHost.Service1', provided as the Service attribute value in the ServiceHost directive could not be found. 

This question is related to c# wcf iis

The answer is


I got this error when trying to add the Service reference for the first Silverlight enabled WCF in the same solution. I just build the .Web project and it started working..


I had the same Exception, this is due to the Type not correctly mentioned in the .svc file

I corrected with below fix.

if your .svc.cs has class like this

namespace Azh.Services.MyApp
{
    public class WcfApp : FI.IWcfAppService
{
...
}
}

for this the .svc file should look like this

<%@ ServiceHost Language="C#" Debug="true" Service="Azh.Services.MyApp.WcfApp" CodeBehind="WcfApp.svc.cs" %>

This error occurs due to mismatch of Service name in .SVC file. Probably you might have changed the name of the service class that is implementing the interface.The Solution is to open .SVC file and exactly match the Service attribute and CodeBehind Attribute. So your .SVC file should be like

<%@ ServiceHost Language="Language you are using" Debug="bool value to enable debugging" Service="Service class name that is implementing your Service interface" Codebehind="~/Appcode/Class implementing interface.cs"%>. for eg.

<%@ ServiceHost Language="C#" Debug="true" Service="Product.Service" CodeBehind="~/AppCode/Product.Service.cs"%>

This example is for .svc file that is using C# language, with debugging enabled, Service class implementing interface and this class is within app folder with name Service.cs and Product is namespace for Service class.

Also Please make respective change in service config file.

<system.serviceModel>
    <services>
        <service name="Product.Service" behaviorConfiguration="ServiceBehavior">
            <endpoint address="" binding="wsHttpBinding" contract="Product.Iservice">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <behavior name="ServiceBehavior">
            <serviceMetaData httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
    </behaviors>
</system.serviceModel>

I had this problem - my service type was in the GAC. It WOULD work if i added the dll containing the type to the bin folder but as it was in the GAC this was NOT what I wanted. I eventually added this to the web.config for the service

<system.web>
    <customErrors mode="RemoteOnly" />
    <compilation debug="true" targetFramework="4.0">
        <assemblies>
            <add assembly="[name in GAC], Version=[version in GAC], Culture=neutral, PublicKeyToken=[ac token]" />
        </assemblies>
    </compilation>
</system.web>

and it worked without needing any dlls in the bin folder.


I faced with this error today, reason was; IIS user doesn't have permission to reach to the application folder. I gave the read permissions to the app root folder.


If you have renamed anything verify the (Properties/) AssemblyInfo.cs is correct, as well as the header in the service file.

ServiceName.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Company.Namespace.WcfApp" CodeBehind="WcfApp.svc.cs" %>

Aligning with your namespace in your Service.svc.cs


I had the same problem, found this thread, tried all but nogo.

Then I spend another 4 hours wasted time.

Then I found that the compilation settings had changed from 64bits to x86. When I changed it back to 64bits it worked. Don't know exactly why but could be that the IIS application pool was not set to allow 32 bit applications.


Two keys to this for certain flavors of the ' Service attribute value in the ServiceHost directive could not be found'-problem: (1) If you're working in Silverlight, you should use the Silverlight WCF-Enabled Service, not the non-Silverlight WCF Service; this will update Web.Config for the bindings and allow the type to be visible; (2) Match the class name in the new service to the Service name -- the goal here is to make a wsdl... so that you know the service's functionality is exposed to your Silverlight client and to the Web; it helps to have the service match the class. If you get the names gummed up, you will have to edit the Web.Config in 3 places (serviceBehaviors, services and bindings).

There were so many sincere attempts to help folks with this problem that were not helpful to me that it should be stressed that this write-up is for a Silverlight solution and it may not apply for someone not using Silverlight 3 in a client/Web configuration.

Hope it helps.


I practically solved the same issue . Here is my suggestion -- The error means that the object referenced in the Service attribute is not found. For the object to be found, the application or library must build output to the bin folder.

You can edit property page of the application and specify the output path to 'bin'.


This may sound trivial, but worth mentioning: You have to build the service (in Visual Studio) - then a DLL will be created in the bin subfolder.

When the service is "deployed" on a server - that bin folder needs to have that DLL file in it - otherwise this error will be thrown...


You should configure your bin folder path to service local bin.


The problem could also be a in a different namespace in svc file as it is in svc.cs file.

In svc file namespace must be in the following format.

Service="Namespace.SvcClassName"

I had the same problem but no clue what caused it. I Solved it by changing from Debug to Release and Run using Debug/Start New Instance. After that, it ran in both Release and Debug. It was magic...


Double check that you're referencing the correct type from the ServiceHost directive in the .svc file. Here's how...

  1. In the VS project containing your web service, open the .svc file in the XML editor (right-click the file, Open With..., choose XML (Text) Editor, OK).
  2. Note the "Service" attribute value.
  3. Make sure it matches the fully qualified type name of your service. This includes the namespace + type name. For example, if the namespace is "MyCompany.Department.Services" and the class is called "MyService", then the Service attribute value should be "MyCompany.Department.Services.MyService".

I had my service dll's in the bin folder where the svc file was residing. Moving the dll's to the root bin folder solved the problem.


Building the solution before adding the service reference solved my problem.


Add reference of service in your service or copy dll.


  1. Make sure markup (svc) file has service attribute with namespace.classname and codebehind will be classname.svc.cs

  2. Rebuild the solution

  3. Restart the app pools from local IIS once.


In my case Right Click on Virtual Directory and Select "Convert To Application" worked!


I also ran into this issue trying the Microsoft.ServiceModel.Samples.Calculator WCF sample. I am using IIS 5.1. I resolved it by ensuring that the website that was auto-generated (servicemodelsamples) was not an application. Right-click the folder, click "Properties" and click the "Create" button.


I know this is probably the "obvious" answer, but it tripped me up for a bit. Make sure there's a dll for the project in the bin folder. When the service was published, the guy who published it deleted the dlls because he thought they were in the GAC. The one specifically for the project (QS.DialogManager.Communication.IISHost.RecipientService.dll, in this case) wasn't there.

Same error for a VERY different reason.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to wcf

Create a asmx web service in C# using visual studio 2013 WCF Exception: Could not find a base address that matches scheme http for the endpoint WCF Service, the type provided as the service attribute values…could not be found WCF error - There was no endpoint listening at How can I pass a username/password in the header to a SOAP WCF Service The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'NTLM' Content Type application/soap+xml; charset=utf-8 was not supported by service The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8) maxReceivedMessageSize and maxBufferSize in app.config how to generate a unique token which expires after 24 hours?

Examples related to iis

ASP.NET Core 1.0 on IIS error 502.5 CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default Publish to IIS, setting Environment Variable IIS Manager in Windows 10 The page cannot be displayed because an internal server error has occurred on server The service cannot accept control messages at this time NuGet: 'X' already has a dependency defined for 'Y' Changing project port number in Visual Studio 2013 System.Data.SqlClient.SqlException: Login failed for user "This operation requires IIS integrated pipeline mode."