相关疑难解决方法(0)

Visual Studio 2017 - 无法加载文件或程序集"System.Runtime,Version = 4.1.0.0"或其依赖项之一

我正在使用Visual Studio 2017,我正在尝试创建.Net Standard 1.5库并在.Net 4.6.2 nUnit测试项目中使用它.

我收到以下错误...

无法加载文件或程序集'System.Runtime,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.该系统找不到指定的文件.

我尝试过以下方法:

  1. 参考Std库作为项目参考.错误:给我以前的错误.
  2. 为我的Std库创建一个NuGet pkg并引用它.错误:类型是System.String,期望System.String.这是因为System.Runtime最终被项目引用,并且它具有所有标准类型的定义.
  3. 参考NuGet pkg NetStandard.Library.错误:给我与#相同的错误("类型是System.String,期望System.String").注意:在我这样做之前,我清除了项目中的所有NuGet包,然后只添加了nUnit和NetStandard.Library包(安装了45个其他包).

这是一个错误吗?有解决方法吗?任何帮助表示赞赏.

.net visual-studio-2017 .net-standard-1.5

89
推荐指数
7
解决办法
7万
查看次数

HttpResponseMessage无法在Web Api(.NET 4.5)中工作

我阅读http://www.asp.net/web-api/overview/security/working-with-ssl-in-web-api并尝试使用该页面中的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Http.Filters;
using System.Web.Http.Controllers;

public class RequireHttpsAttribute : AuthorizationFilterAttribute
{
    public override void OnAuthorization(HttpActionContext actionContext)
    {
        if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
        {
            actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
            {
                ReasonPhrase = "HTTPS Required"
            };
        }
        else
        {
            base.OnAuthorization(actionContext);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我构建时,我没有收到错误,但运行时给出了这个错误:

CS0012:类型'System.Net.Http.HttpRequestMessage'在未引用的程序集中定义.您必须添加对程序集'System.Net.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'的引用.

我的项目的参考文件夹中有一个对System.Net.Http的引用.如果我查看它的属性,它会说版本4.0.0.0和运行版本4.0.30319.我的项目属性说目标框架是.NET 4.5.

我在VS2013 Express中的IntelliSense也不想接受与HttpResponseMessage或HttpRequestMessage有关的任何事情.

我已经尝试删除引用并重新添加它,但无济于事.

任何帮助将非常感激.

c# asp.net-web-api

9
推荐指数
2
解决办法
1万
查看次数