vivanov
vivanov

Reputation: 97

Can't use oracle managed driver in ASP.NET Core 1 app

I am trying to move from ASP.NET Core RC1 to 1.0.0-preview2 but having problems using Oracle managed driver that was working before. I am getting a following error trying to create a new OracleConnection:

Error CS0012 The type 'DbConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Ludens.Data..NETCoreApp,Version=v1.0 16 Active

Here is a code where I use it:

using System;
using Oracle.ManagedDataAccess.Client;
using Microsoft.Extensions.Options;
using Ludens.Common;
using System.Data;

namespace Ludens.Data
{
  public class LegacyContext : IDisposable
  {
    public IDbConnection Connection { get; }

    public LegacyContext(IOptions<LudensSettings> options)
    {
      var appSettings = options.Value;
      Connection = new OracleConnection(appSettings.Oracle.Connection);
      Connection.Open();
    }

    public void Dispose()
    {
      Connection.Dispose();
    }
  }
}

Also here is my package.json:

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Dapper": "1.50.0",
    "Oracle.ManagedDataAccess": "12.1.24160419",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Ludens.Common": "1.0.0"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8",
        "net451"
      ]
    }
  }
}

I have a feeling that I incorrectly specify dependencies but figure out what I am missing. Please advice.

Upvotes: 2

Views: 3376

Answers (2)

Devvox93
Devvox93

Reputation: 316

I was getting that DbConnection error, too. What worked for me is adding the reference to System.Data, which basically the error tells you to do. It took me a while to figure it out, too.

So in short:

  • Right click on "References" of your project.
  • Click "Add Reference..."
  • From .NET Framework 4.6.1 (or similar), select "System.Data" and click OK.
  • VS will process the changes and the errors will disappear.

Upvotes: 0

Gary Holland
Gary Holland

Reputation: 2645

As was noted by @LexLi Oracle doesn't yet support .net core so you won't be able to target netcoreapp1.0.

However, if you're only targeting windows platform, you can simply target a supported .net framework:

"frameworks": {
  "net451": { }
}

This will at least allow you to develop in .net core, and when Oracle support does arrive, upgrading should just be a matter of amending your project.json.

Note, if you want to use the Entity Framework 7 against Oracle, this still won't work, you'll need to wait for a supported library.

Upvotes: 3

Related Questions