Web-api-selfhost应用程序中的编译错误 [英] Compile error in web-api-selfhost application

查看:165
本文介绍了Web-api-selfhost应用程序中的编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图创建一个web-api-selfhost应用程序,但最终出现了异常.这是导致错误的代码.

Hello all,

I was trying to create a web-api-selfhost application, But ended up with an exception. Here is my code which caused the error.

var config = new HttpSelfHostConfiguration("http://localhost:8080");

config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",new { id = RouteParameter.Optional });//This line caused error

            using (HttpSelfHostServer server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();

                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }


这是我收到的例外.


This is the exception which I have received.

The type 'System.Web.Routing.RouteCollection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.


我应该导入其他名称空间吗?任何帮助,将不胜感激.

谢谢&问候
Sebastian


Should I import any other namespace? Any help on this would be appreciated.

Thanks & Regards
Sebastian

推荐答案

我已经通过添加system.web作为参考来解决了这个问题.

谢谢
塞巴斯蒂安
I have solved this myself, by adding system.web as a reference.

Thanks
Sebastian


这篇关于Web-api-selfhost应用程序中的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆