73

I've got a Client/Server wcf application

My executable doesn't define any ServiceContract, it doesn't even have a reference to System.ServiceModel (but instead has a reference to an assembly which contains the connection logic to the server)

I've another assembly, which is referenced by my EXE, which contains a ServiceContract.

It used to work fine. Yesterday, I've played a lot with my project settings (partial trust, full trust, deployment settings, and so on) and now, each and every time I launch my client, I've got the following message box :

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

Then VS freezes for 1 minute, and eventually lets me debug my program as usual.

I've found a post on this problem, but the solution doesn't apply in my situation. Any ideas?

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
Brann
  • 31,689
  • 32
  • 113
  • 162

9 Answers9

121

It's always like that. You search for 2 hours, you eventually end up posting on SO, and 5 minutes later, you find the answer.

In the WCF Options tab of the properties of the project defining the ServiceContract, there's a checkbox labelled "Start WCF Service Host when debugging another project in the same solution" that I unchecked.

I've no idea how it has been checked in the first place.

Anyway, that solved my problem. See the MSDN Reference for this project setting.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
Brann
  • 31,689
  • 32
  • 113
  • 162
  • 1
    Where is this in visual studio 2010? – joncodo Aug 19 '11 at 11:54
  • 3
    @Jonathan: my bet is that you're not looking at the properties of the correct project. You need to select the project *defining* the contract; not the one implementing it nor the one calling it. – Brann Aug 19 '11 at 12:30
  • Thanks Brann, you were right about it. It is in the same place in 2010 – joncodo Aug 19 '11 at 13:04
  • I'm seeing this same issue and the project defining the contract doesn't have a WCF options tab. It's infuriating... – Omar Kooheji May 14 '12 at 11:28
  • I'm looking in my WCF Web Service Project, my actual WCF service project. The properties have nothing to that effect. – PositiveGuy Nov 04 '13 at 03:19
  • 1
    This solved my issue. I think it's because I have the service defined in a different project from which it's implemented. – puddinman13 Apr 10 '15 at 15:21
12

Just in case anyone else is looking for an answer, another cause of this error can be if you happen to have an App.config file in a project that is a Class Library that has a <system.serviceModel> section.

I moved service code out of a project that was an executable to a different project but accidentally left the old App.config file. My new project, which was a Console application programatically configured and started WCF, but because the old App.config file was in the referenced assembly, I would get that cryptic dialog box even when debugging the Console application.

Took about 12 hours to track this one down since I didn't realize that VS debugger checks all referenced assemblies for App.config which have WCF services configured.

bpeikes
  • 3,495
  • 9
  • 42
  • 80
9

To determine project with this problem find string 3D9AD99F-2412-4246-B90B-4EAA41C64699 in your project files.

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

Then turn off project option "WCF Options/Start WCF Service Host when debugging another project in the same solution"

  • 1
    While this solution might resolve the matter for some folks, at least in vs2015 it will remove "Publish" from the context menu when right-clicking on the WCF project... – Ricardo Appleton Aug 26 '16 at 15:34
  • 1
    Yes this will help us find which project we have mistakenly checked the "Start WCF Service Host when ..." as @Brann pointed out. I am using the following command to find which project has the setting: c:\MyProjects>findstr /s /m "3D9AD99F-2412-4246-B90B-4EAA41C64699" *.csproj – wcb1 Nov 28 '19 at 18:46
4

Some blogs say, it might have happend because of copying the project from a different branch, that overrides GUIDs... so just delete them as explained in this blog.

Stacked
  • 6,892
  • 7
  • 57
  • 73
HydPhani
  • 592
  • 6
  • 13
2

This error can also be caused by a wrong service name in your config file:

<system.serviceModel>
    <services>
      <service name="MyServiceLibrary.WrongServiceName">
...

Check your config file and be sure the service name is correct.

Stacked
  • 6,892
  • 7
  • 57
  • 73
2

In my case the problem was, because one of the normal class library project (that was referenced by the WCF service library) had this in it's .csproj file:

<ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{3D9AD99F-2412-4246-B90B-4EAA41C64699}">
        <WcfProjectProperties>
          <AutoStart>True</AutoStart>
        </WcfProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>

Changing this to False solved the problem. This answer was already there, but make sure that you checked all projects, not just the WCF service library one.

Muzzy
  • 53
  • 5
1

I also went through the same kind of problem and searched for hours to get rid of this particular error. Finally i did find out a way out of it.

When you come across this particular problem, you try to run your both server and client application as administrator, and change the WPF properties of project.

When you click the WPF properties of the project, you will find a build option. In build option, there is a option called PLATFORM TARGET, in which you can change the platform target to x86. Also note that in case of x84, you need to set it to x84.

Now run your project from console, i.e. go to the folder where your projects are saved and in the bin of client, you will find a folder debug where you will get your console application. You should now be able to run the application successfully.

Kjartan
  • 18,591
  • 15
  • 71
  • 96
1

Old thread. Just remove any commandline arguments from the Debug section in Options. That helped me.

BlueHeaven
  • 11
  • 2
0

Adding another solution since this message seems to have multiple causes. Removing the following GUID from the ProjectTypeGuids tag in the project file resolved the issue.

<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699}</ProjectTypeGuids>
tgriffin
  • 483
  • 1
  • 5
  • 13