Skip Navigation LinksHome > View Post
WCF: The type provided as the Service attribute could not be found

This had me stumped for a little while today. Whilst trying to host a WCF service in IIS we got this message when we tried to access the .svc file:

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

At first the message seemed to be very specific about not being able to find the type - almost as though it had found the assembly so I changed the YourAssembly to utter nonsense to see if the error changed. Alas no, so it was possible that the assembly couldn't be 'found', let alone the type.

Everything seemed to be in order as far as the assembly was concerned. He was in the bin folder and security was setup appropriately. The type, namespace and assembly were quadruple checked and definitely correct. We even hooked up WinDbg and used the sxe ld YourAssembly command in the hope that we'd see the module attempt to load and fail. But nothing.

So I did what I always do in these situations and reverted to my ol' skool Response.Write-ASP-classic-style debugging techniques. First step was to drop in an aspx page that used the Activator to create the type dynamically. Here's the ASPX page (no .aspx.cs required):

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Runtime.Remoting" %>

<%
ObjectHandle oh = Activator.CreateInstance("YourType", "YourAssembly");
Response.Write(oh.Unwrap().ToString() + " loaded OK");
%>


Just drop this page next to your .svc file and navigate to it in the browser. If it works and you can see the name of your type then you have a different problem to ours. I got an error that looked like this:

Could not load file or assembly 'SomeOtherAssembly' or one of its dependencies. The system cannot find the file specified.

Aha! So we could find the type specified in the Service attribute but we couldn't find some of its dependences. That's better - turns out I was missing an assembly that had to be GAC'd for this to work.

Tags: WCF

Josh Post By Josh Twist
10:25
12 Aug 2008

» Next Post: Databinding to property bags and dictionaries in WPF
« Previous Post: Why does Visual Studio keep checking some project files out?

Comments:

Posted by Darren Jefford @ 12 Aug 2008 15:12
Fusion Log Viewer (FusLogVw) can also help in these circumstances - always one of the first tools I bring out to see what Fusion is up to..

Posted by Matt McGregor @ 06 Jan 2009 03:22
Thanks Josh. This was really stumping me, using your ASPX route pointed out the missing reference I had. You gotta love WCF error messaging!
Cheers
Matt

Posted by Charles @ 12 Jan 2009 13:08
Thanks Josh! In trying to find out why asp.net couldn't find my assembly, I tried your code - and the surprising thing is that it didn't throw an exception! I'm still getting a "The type 'YourType', provided as the Service attribute value in the ServiceHost directive could not be found." error, and I have no idea why.

I see that you used the both the service type and assembly name in your ServiceHost directive, separated by ", " - I have tried that also, but I end up getting the following error:
"An error occurred during the parsing of a resource required to service this request ... The required directive 'ServiceHost' is missing."

Any suggestions? My .svc looks like this:
<%@ServiceHost Service=”BWC.NetServices.Ordering.OrderService, BWC.NetServices.Ordering” %>

Thanks in advance!
-Charles

Posted by Charles @ 12 Jan 2009 13:17
Doh! Nevermind... Somehow I was using quotes like ”, as opposed to " :D.

Smooth...

Thanks again!
-Charles

Posted by Robert Hellestrae @ 26 Feb 2009 09:16
Thanks for the insight!

What is the missing assembly that is required in the GAC?

Best regards, Rob

Posted by James @ 07 Apr 2009 17:46
Actually, the parameters are ("Assembly", "Type"). :)

Posted by pdschuller @ 22 May 2009 10:54
I had a similar problem that required me to do two things in order to resolve it:

1.) the dll that my web service project created had to be dragged over to the bin directory of the web-site-to-which-I-was-deploying. (The reason I hadnt done this was that "Microsoft .NET Framework 3.5 - Windows Communication Foundation" (p.106) had said that was optional.

2.) when it came time to create a Service Reference in the VS 2008 I was using the IP number like
http://123.123.12.1/Service1.svc/wsdl and I needed to use
http://www.MyDomainName.com/Service1.svc?wsdl
btw, I got that correct url when I browsed to http://123.123.12.1/Service1.svc The IP worked in that case.
HTH

Posted by ongle @ 29 May 2009 16:48
thanks, useful tip

Posted by Smith @ 27 Jul 2009 14:11
Does this method really work?

I just used in my WCF test and all in GAC. I compiled a DLL called "IHelloWorldService.ll"
using System;
using System.Runtime.Serialization;
using System.ServiceModel;

and test.aspx always complianed
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Runtime.Remoting" %>

<%
ObjectHandle oh = Activator.CreateInstance("IHelloWorldService.dll", "IHelloWorldService");
Response.Write(oh.Unwrap().ToString() + " loaded OK");
%>

also tried
("IHelloWorldService", "IHelloWorldService.dll");

Compile error:
System.IO.FileNotFoundException: Could not load file or assembly 'IHelloWorldService.dll' or one of its dependencies. The system cannot find the file specified.

Posted by kapil @ 04 Nov 2009 04:22
I added your code and I got a message
Assembly loaded OK
Not sure why the error is coming while I am trying to run WCF

Posted by vicent @ 15 Nov 2009 17:07
hi ,i met the erroe today,may be you can try add the the the refrence of dll file which implement the ServiceContract

Post a comment:

Name  

E-mail (never shared)

URL

Comments  

Captcha ImageRefresh Image
What's this?
Enter code above