【问题标题】:CS0234: The type or namespace name 'Description' does not exist in the namespace 'System.Web.Http' (are you missing an assembly reference?)CS0234:命名空间“System.Web.Http”中不存在类型或命名空间名称“描述”(您是否缺少程序集引用?)
【发布时间】:2017-05-12 04:44:34
【问题描述】:

我在 ASP.Net MVC WebAPI 中遇到命名空间错误。 我将 MVC 4 与 .Net Framework 4.5 一起使用,在运行应用程序时它可以工作,但在单击 API 时会显示如下错误。

    ------------------------------------------------------------------------------------
    Server Error in '/' Application.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0234: The type or namespace name 'Description' does not exist in the namespace 'System.Web.Http' (are you missing an assembly reference?)

    Source Error:
    Line 1:  @using System.Web.Http
    Line 2:  @using System.Web.Http.Description
    Line 3:  @using System.Collections.ObjectModel
    Line 4:  @using SmartCare360APIs.Areas.HelpPage.Models

    Source File: e:\Projects\SmartCare 360\Code\SmartCare360APIs\SmartCare360APIs\Areas\HelpPage\Views\Help\Index.cshtml    Line: 2

    Show Detailed Compiler Output:
    Show Complete Compilation Source:

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1637.0
    -----------------------------------------------------------------------------------

下面是缺少命名空间的地方。 我尝试重新安装 mvc 4,但它带来了更多错误。

Page : **ApiGroup.cshtml**

 @using System.Web.Http
 @using System.Web.Http.Description
 @using SmartCare360APIs.Areas.HelpPage
 @using SmartCare360APIs.Areas.HelpPage.Models
 @model IGrouping<string, ApiDescription>

 <h2 id="@Model.Key">@Model.Key</h2>
 <table class="help-page-table">
 <thead>
                <tr><th>API</th><th>Description</th></tr>
            </thead>
            <tbody>
            @foreach (var api in Model)
            {
                <tr>
                    <td class="api-name"><a href="@Url.Action("Api", "Help", new { apiId = api.GetFriendlyId() })">@api.HttpMethod.Method @api.RelativePath</a></td>
                    <td class="api-documentation">
                    @if (api.Documentation != null)
                    {
                        <p>@api.Documentation</p>
                    }
                    else
                    {
                        <p>No documentation available.</p>
                    }
                    </td>
                </tr>
            }
            </tbody>
        </table>

【问题讨论】:

    标签: c# asp.net-mvc-4 asp.net-web-api


    【解决方案1】:

    尝试以下方法:

    1) 尝试在 References\System.Web.Http 的“属性”选项卡中设置“复制本地:true”

    2) 如果上述方法不起作用,请尝试在 NuGet 包控制台中卸载 Microsoft.AspNet.WebApi 包,然后重新安装。

    【讨论】:

      【解决方案2】:

      有时对 System.Web 的引用无法识别正确的版本。

      尝试使用添加参考上的浏览选项手动添加它。

      【讨论】:

        【解决方案3】:

        这是 .Net 框架问题。 我已将 .Net 框架更新到最新版本,并且错误消失了。 我仍然不确定这是否是解决方案,但不知何故它对我有用。

        感谢您的回复!

        【讨论】:

          猜你喜欢
          • 2017-05-01
          • 2020-12-17
          • 2021-06-14
          • 1970-01-01
          • 1970-01-01
          • 2014-03-28
          • 2015-02-14
          • 1970-01-01
          • 2017-05-04
          相关资源
          最近更新 更多