After upgrading to .NET core 1.0 using framework net46 I'm getting the following exception:
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)
It happens at runtime just before trying to enter the method called GetNumbersForMainScreen, which contains the following lines of code:
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;
}
Here the variable connection is of type IDbConnection and QueryMultiple is an extension method from Dapper v1.50.2.0.
I'm quite puzzled about this. The code compiles just fine but at runtime I'm told, that the method does not exist.
I assume it is an issue related to mismatch in the version of the underlying dependencies. In Java using Maven or similar tools I would run some dependency analysis looking for versioning conflicts in the dependency tree, but I don't know how to troubleshoot this kind of issue in .NET.
Any suggestions on what causes this problem or how I can troubleshoot this kind of issue will be appreciated.
Edit 2016-08-25: My project.json looks like this:
{
"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%" ]
}
}
The problem is that that you're referencing both Dapper
and Dapper-Async
. Dapper-Async
is not a complement of Dapper
, it's a replacement. What this means is that both packages contain Dapper.dll
, so dotnet
is confused about which one to use, and for some reason, uses one at compile time and the other at runtime, causing the exception.
The solution is to use either Dapper
or Dapper-Async
, but not both. As to which one to use, I don't know, since I'm not familiar with Dapper. But my guess is that you should use Dapper
, since Dapper-Async
hasn't been updated in a long time.