.net 如何摆脱 VS2008 中的“目标程序集不包含服务类型”错误消息?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/564541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:09:54  来源:igfitidea点击:

How can I get rid of the "The target assembly contains no service types" error message in VS2008?

.netvisual-studio-2008wcfdebugging

提问by Brann

I've got a Client/Server wcf application

我有一个客户端/服务器 wcf 应用程序

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)

我的可执行文件没有定义任何ServiceContract,它甚至没有对System.ServiceModel而是对包含到服务器的连接逻辑的程序集的引用

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

我有另一个程序集,它被我的 EXE 引用,它包含一个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.

Microsoft WCF 服务宿主
目标程序集不包含服务类型。
您可能需要调整此程序集的代码访问安全策略。

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

然后 VS 冻结 1 分钟,最终让我像往常一样调试我的程序。

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

我找到了关于此问题的帖子,但该解决方案不适用于我的情况。有任何想法吗?

回答by Brann

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.

总是这样。您搜索了 2 个小时,最终在 SO 上发帖,5 分钟后,您找到了答案。

In the WCF Optionstab 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.

在定义 的项目属性的“ WCF 选项”选项卡中ServiceContract有一个标记为“在同一解决方案中调试另一个项目时启动 WCF 服务主机”的复选框,我没有选中它。

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

我不知道它最初是如何检查的。

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

无论如何,这解决了我的问题。有关此项目设置,请参阅MSDN 参考

回答by bpeikes

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

以防万一其他人正在寻找答案,此错误的另一个原因可能是您碰巧App.config在项目中拥有一个文件,该文件是具有<system.serviceModel>部分的类库。

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

我将服务代码从一个项目中移出,该项目是另一个项目的可执行文件,但不小心留下了旧App.config文件。我的新项目是一个以编程方式配置并启动 WCF 的控制台应用程序,但由于旧App.config文件在引用的程序集中,即使在调试控制台应用程序时,我也会得到那个神秘的对话框。

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.

花了大约 12 个小时来跟踪这个问题,因为我没有意识到 VS 调试器会检查所有引用的 App.config 程序集,这些程序集配置了 WCF 服务。

回答by alexey.petriashev

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

要确定存在此问题的项目,请在项目文件中查找字符串 3D9AD99F-2412-4246-B90B-4EAA41C64699。

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

例子: <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"

然后关闭项目选项“WCF 选项/在同一解决方案中调试另一个项目时启动 WCF 服务主机”

回答by HydPhani

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.

一些博客说,这可能是因为从不同的分支复制项目而发生的,这会覆盖 GUID……所以只需按照本博客中的说明删除它们

回答by REESHABH CHOUDHARY

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 propertiesof project.

当您遇到此特定问题时,您尝试以管理员身份运行服务器和客户端应用程序,并更改项目的WPF 属性

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.

当您单击项目的 WPF 属性时,您会找到一个构建选项。在构建选项中,有一个名为PLATFORM TARGET的选项,您可以在其中将平台目标更改为x86。另请注意,在x84 的情况下,您需要将其设置为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 debugwhere you will get your console application. You should now be able to run the application successfully.

现在从控制台运行您的项目,即转到保存项目的文件夹,在客户端的 bin 中,您将找到一个文件夹debug,您将在其中获得控制台应用程序。您现在应该能够成功运行应用程序。

回答by Stacked

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.

检查您的配置文件并确保服务名称正确。

回答by BlueHeaven

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

旧线程。只需从选项的调试部分中删除任何命令行参数。那帮助了我。

回答by tgriffin

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 标记中删除以下 GUID 解决了该问题。

<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699}</ProjectTypeGuids>