Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems in Dapper and MVC VNext

I created an class library for tests of an ASP.NET MVC VNext project.

In this class library I am using Dapper so I have the project.json:

{

  "dependencies": {
    "xunit": "2.1.0-beta2-*",
    "xunit.runner.dnx": "2.1.0-beta2-*",
    "Dapper": "1.42.0"
  },

  "commands": {
    "test": "xunit.runner.dnx"
  },

  "frameworks": {

    "dnx451": {
      "dependencies": {
        "Dapper": "1.42.0"
      }
    },

    "dnxcore50": {
      "dependencies": {
        "System.Collections": "4.0.10-beta-22816",
        "System.Linq": "4.0.0-beta-22816",
        "Microsoft.CSharp": "4.0.0-beta-22816",
        "Dapper": "1.42.0"
      }
    }

  }
}

I keep getting the error:

The type or namespace name 'Dapper' could not be found (are you missing a using directive or an assembly reference?)    MvcProj.Test.DNX Core 5.0   

How can I fix this?

like image 370
Miguel Moura Avatar asked Jun 30 '15 16:06

Miguel Moura


2 Answers

Use a beta version of Dapper

Since dnxcore50 is still in beta, none of the release versions of Dapper can claim release support for it it yet. That's why the Dapper guys aren't putting it in the release packages.

DNX beta support is available in the beta versions of Dapper. Try using version 1.41.0-beta5, or whatever the latest non-release version is in their nuget feed.

"dependencies": {
    //...
    "System.Data.SqlClient": "4.0.0-beta-23225",
    "Dapper": "1.41.0-beta5"
},

I'm using this in my applications right now and it seems to work well.

like image 126
Matt Avatar answered Sep 21 '22 23:09

Matt


The problem you're seeing is due to Dapper not having built a package for dnxcore50 (CoreCLR). There are 3 ways you can resolve this.

  1. Remove the "dnxcore50" node from your project.json (this means you will not be building against dnxcore50 anymore).
  2. In your application code, where you're using Dapper surround those pieces of code with ifdefs: #if DNX451 .... #endif. This then makes you're application only use Dapper in the dnx451 build configuration.
  3. Convert Dapper to build for dnxcore50. This would require getting the source code and making necessary changes to work on dnxcore50.
like image 21
N. Taylor Mullen Avatar answered Sep 21 '22 23:09

N. Taylor Mullen