【发布时间】:2016-09-01 06:01:33
【问题描述】:
使用框架 net46 升级到 .NET core 1.0 后,出现以下异常:
System.MissingMethodException was unhandled by user code
HResult=-2146233069
Message=Method not found: 'System.Collections.Generic.IEnumerable`1<!!0> GridReader.Read(Boolean)'.
Source=Sdm.Web
StackTrace:
at Sdm.Web.SqlAccess.SqlMgr.GetNumbersForMainScreen(TenantId tenantId)
at Sdm.Web.Test.TestDrivers.SqlMgrTestDriver.TestGetNumbersForMainScreen() in ...\Unittest\SqlMgrTestDriver.cs:line 37
InnerException: (null)
它发生在运行时,就在尝试进入名为 GetNumbersForMainScreen 的方法之前,该方法包含以下代码行:
using (SqlMapper.GridReader result = connection.QueryMultiple(SqlGetNumbersForMainScreen, new { recent = recent, tid = tenantId.Id }))
{
var val = new NumbersForMain()
{
AlarmsCriticalCount = result.Read<int>().Single(),
AlarmsNoncriticalCount = result.Read<int>().Single(),
RoomsCount = result.Read<int>().Single(),
UnitsOnlineCount = result.Read<int>().Single(),
UnitsCount = result.Read<int>().Single(),
};
val.UnitsOfflineCount = val.UnitsCount - val.UnitsOnlineCount;
return val;
}
这里的变量 connection 是 IDbConnection 类型,QueryMultiple 是 Dapper v1.50.2.0 的扩展方法。
我对此感到很困惑。代码编译得很好,但在运行时我被告知,该方法不存在。
我认为这是与底层依赖项版本不匹配有关的问题。在使用 Maven 或类似工具的 Java 中,我会运行一些依赖关系分析,以查找依赖关系树中的版本控制冲突,但我不知道如何在 .NET 中解决此类问题。
任何有关导致此问题的原因或我如何解决此类问题的建议将不胜感激。
编辑 2016-08-25: 我的 project.json 看起来像这样:
{
"userSecretsId": "XXX",
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"dependencies": {
"Dapper": "1.50.2",
"Dapper-Async": "1.3.0",
"EntityFramework": "6.1.3",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
"Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.0.0",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.Elm": "0.1.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0",
"Microsoft.Extensions.Caching.Memory": "1.0.0",
"Newtonsoft.Json": "9.0.1",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
"Microsoft.AspNetCore.Authorization": "1.0.0",
"Microsoft.Azure.Devices": "1.0.5",
"Microsoft.AspNetCore.HttpOverrides": "1.0.0",
"EFAttributeConfig": "1.0.0",
"Twilio": "4.5.0",
"Sendgrid": "6.3.4",
"Microsoft.AspNetCore.Routing": "1.0.0",
"Microsoft.AspNetCore.Hosting": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"log4net": "2.0.5"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net46": { }
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config",
"log4net.xml"
],
"exclude": [
"**.user",
"**.vspscc"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
【问题讨论】:
-
你能发布你的 project.json 吗?
-
我最终重写了上面的代码,从而避免了 QueryMultiple,现在它可以工作了。我仍然很好奇如何解决 .NET Core 中的依赖冲突。
-
我的 project.json 已添加到问题中。