"The target assembly contains no service types. You may need to adjust the Code Access Security policy of this assembly." annoyance

by Miha Markič 10. March 2008 10:45

Did you ever encounter this dialog box when dealing with WCF services?

"The target assembly contains no service types.  You may need to adjust the Code Access Security policy of this assembly."

It might happen when you run application at debug time. It is highly annoying and time consuming (it pauses application for more than one minute without any apparent reason). But what does it mean and why does it happen?

When you create a project from a WCF project templates Visual Studio knows that this project is a WCF service and thus it offers two debug time helpers: WCF Service Host and WCF Client. These two guys are intended to help you with running and testing WCF services without writing any code - they just appear at debug time. So far so good. But why the annoying dialog?

The dialog in question means that you have a project, created using one of the WCF project templates, with an interface marked with ServiceContract attribute and in the same project you don't have a class that implements this interface (perhaps you implemented that interface in another project). So, the WCF Service Host can't find a suitable class to host the service and it complains through that dreaded dialog box. Note that WCF Service Host is pretty dumb and it is incapable of searching through other projects in same solution. OK, the solution is to stop running WCF Service Host or even better, instruct it which class implements the interface in question. Well, AFAIK the later is impossible while the former can be done through project file modification using notepad. Here is how:

Delete this line from your project file:

<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

And you won't see WCF Service Host or dreaded dialog anymore.

The question is, why didn't [MS] think of these scenarios before?

BTW, if you just want to stop WCF Client from runing then delete this command line argument: /client:"WcfTestClient.exe", created by WCF project template.

Tags:

WCF | .net 3.5

Comments (6) -

Raghu
Raghu
3/18/2008 1:51:50 AM #

Thanks.. your tip saved me couple of hours of my research.

Reply

Peter Schnupp
Peter Schnupp
4/16/2008 7:20:23 PM #

Sorry, where must I delete which line:

-------------------------------------------

Delete this line from your project file:


{3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}

And you won't see WCF Service Host or dreaded dialog anymore.

----------------------------------------

My browser only shows a horizontal scroll bar instead of the stuff.

Thanks a lot,

Peter

Reply

Miha Markic
Miha Markic
4/21/2008 4:28:55 PM #

You have to delete from project file (.csproj or .vbproj or some else, depending on the project language):

{3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}


You have to open the file in question in text editor application, i.e. notepad.exe.

Reply

George
George
6/8/2008 9:44:51 AM #

Thanks for sharing that, but I tried it and it caused my Test Project (which has that value deleted) kind of disabled and not being able to run any test.

Reply

Kjetil Nordahl
Kjetil Nordahl Norway
3/10/2011 6:42:30 PM #

Thanks for explaining the reason for this error.
Just got the same problem in VS2010, and from what you wrote I found that now there is an option in the project settings!

Right-click the project where the interface is defined, select Properties.
Select the "WCF Options" and clear the "Start WCF Service Host when debugging another project in the same solution" checkbox.

Reply

Miha Markic
Miha Markic Slovenia
3/10/2011 6:59:37 PM #

Yes, indeed Visual Studio 2010 has such (welcome) option. Thanks for the update.

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Miha Markic

About me
Righthand
 
Microsoft MVP
 
Developer Express' DXSquad
INETA Country Leader for Slovenia
INETA Country Leader for Slovenia

Slovene Developer Users Group Lead
Friends of Red-Gate
LLBLGenPro Partner

Miha currently works as a free lance consultant and software developer specialized in .net area.
He graduated in Computer and information science at the University of Ljubljana, Slovenia. He has accumulated experience in various programming languages such as Java, Visual Basic 3-6 (MCP), Visual C++, Delphi, C# and VB.Net through years.
He has experience in practically all (technical) stages of project development, including planning, framework development, user interface, business processes, as well as testing and documenting. He has worked on big and small projects in Slovenia and abroad (e.g. participated in completing level 3 IS for the Nucor steel plant, Hertford, USA).
Currently he enjoys programming in .net environment using C#. Since 2000 he has been active in Developer Express' DX Squad and has been ECDL trainer and tester. He also gives lectures on conferences and other events in Slovenia.

Month List

Tag cloud

Most comments

Paulius Paulius
1 comments
us United States
Meh Meh
1 comments
us United States
bart dm bart dm
1 comments
nl Netherlands

RecentComments

Comment RSS