使用分布式缓存(SQL Server)时,ASP.NET Core RC2在完整的.NET Framework上崩溃



我有一个使用ASP.NET Core RC2和dotnet CLI的web项目,目标是刚刚从ASP.NET 5 RC1和DNX更新的.NET Framework。一旦我使用分布式SQL Server缓存,它就会崩溃,出现以下异常:

FileNotFoundException:无法加载文件或程序集"System.Collections.NonGeneric,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"或其依赖项之一。系统找不到指定的文件
System.Data.SqlClient.SqlConnectionString.ctor(字符串连接字符串)

带有堆栈跟踪:

System.Data.SqlClient.SqlConnectionString.ctor(字符串连接字符串)System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString,DbConnectionOptions先前版本)System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey密钥、DbConnectionPoolGroupOptions池选项、DbConnectionOptions和userConnectionOptions)System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey键)System.Data.SqlClient.SqlConnection.set_ConnectionString(字符串值)System.Data.SqlClient.SqlConnection.ctor(字符串连接字符串)Microsoft.Extensions.Cacheching.SqlServer.DatabaseOperations.GetCacheItem(字符串键,布尔值includeValue)Microsoft.Extensions.Cacheching.SqlServer.DatabaseOperations.GetCacheItem(字符串键)Microsoft.Extensions.Cacheching.SqlServer.SqlServerCache.Get(字符串键)Microsoft.AspNetCore.Session.DistributedSession.Load()Microsoft.AspNetCore.Session.DistributedSession.Remote(字符串键)MYCODE.cs等中的MYCODE.SessionHelper.SetValue(字符串键、字符串值)

这行实际上只是Session.Remove(key);

我怀疑它是出于某种原因试图加载.NET Core包,而不是意识到它可以使用.NET Framework。下面是我的项目.json.

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-MYCODE-2d5ac1d3-01c8-4be2-9be2-894efd942480",
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
  "runtimeOptions": {
    "gcServer": false,
    "gcConcurrent": true
  },
  "dependencies": {
    //"Microsoft.NETCore.Platforms": "1.0.1-rc2-24027",
    //"NETStandard.Library": "1.5.0-rc2-24027",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "MYOTHERCODE": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
    "Microsoft.Extensions.Options": "1.0.0-rc2-final",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "System.Text.Encodings.Web": "4.0.0-rc2-24027",
    "Newtonsoft.Json.Schema": "2.0.2",
    "OtpSharp": "1.3.0.4",
    "Microsoft.AspNetCore.Session": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Razor": "1.0.0-rc2-final",
    "Microsoft.Extensions.Caching.SqlServer": "1.0.0-rc2-final",
    "Microsoft.CodeAnalysis.CSharp": "1.3.0-beta1-20160429-01",
    "Microsoft.CodeAnalysis.Workspaces.Common": "1.3.0-beta1-20160429-01",
    "Newtonsoft.Json": "8.0.3",
    "Twilio": "4.7.1"
  },
  "frameworks": {
    "net46": {
      "imports": [ "dnx451" ],
      "frameworkAssemblies": {
        "System.Runtime.Serialization": "4.0.0.0"
      }
    }    
  },
  "runtimes": {
    "win7-x64": {}
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Microsoft.Extensions.SecretManager.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "appsettings.*.json",
      "web.config"
    ]
  }
}

dependencies中添加Microsoft.NETCore.Platforms1.0.1-rc2-24027)和/或NETStandard.Library1.5.0-rc2-24027)的条目没有帮助。由于描述如何做到这一点的文档缺乏甚至根本不存在,我可能在针对.NET Framework方面做了一些错误的事情。唯一的问题是什么?我是否缺少导入或引用程序集或其他什么?

我不确定到底是什么解决了这个问题,但删除dnx451导入并转到net451成功了。这引发了另一个问题,即我用于数据库和迁移的类库将无法运行dotnet ef工具——它必须被制作成一个应用程序才能做到这一点,并且一些配置更改和简单地清空bin和obj文件夹的组合最终将问题解决。

最新更新