Problem running dotnet Core Example in VS Code - (ODP.NET Database Connections: Using Connect Descri — oracle-tech

    Forum Stats

  • 3,715,652 Users
  • 2,242,819 Discussions
  • 7,845,478 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Problem running dotnet Core Example in VS Code - (ODP.NET Database Connections: Using Connect Descri

user552932
user552932 Member Posts: 5
edited August 2019 in ODP.NET

Hi there … hope someone can help

I have tried to follow the tutorial (ODP.NET Database Connections: Using Connect Descriptors and Net Service Names) from Alex Keh - https://www.youtube.com/watch?v=k3wLHQALZRk

But find that I am having problems with the Oracle.ManagedDataAccess.Client

Using VS Code

Building an identical console App as in the tutorial – but when try to run get the following error

Exception has occurred: CLR/System.TypeInitializationException

An unhandled exception of type 'System.TypeInitializationException' occurred in Oracle.ManagedDataAccess.dll: 'The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception.'

Inner exceptions found, see $exception in variables window for more details.

Innermost exception System.IO.FileNotFoundException : Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

   at OracleInternal.Common.ConfigBaseClass.GetInstance(Boolean bIsManaged)

   at OracleInternal.Common.ProviderConfig..cctor()

Also, see the following in the terminal

Executing task: C:\Program Files\dotnet\dotnet.exe build C:\Users\u203379\MyWork\ASPNet\core_console_ora/core_console_ora.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <

Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core

Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\u203379\MyWork\ASPNet\core_console_ora\core_console_ora.csproj : warning NU1701: Package 'Oracle.ManagedDataAccess 19.3.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.

  Restore completed in 28.4 ms for C:\Users\u203379\MyWork\ASPNet\core_console_ora\core_console_ora.csproj.

C:\Users\u203379\MyWork\ASPNet\core_console_ora\core_console_ora.csproj : warning NU1701: Package 'Oracle.ManagedDataAccess 19.3.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.

  core_console_ora -> C:\Users\u203379\MyWork\ASPNet\core_console_ora\bin\Debug\netcoreapp2.2\core_console_ora.dll

Terminal will be reused by tasks, press any key to close it.

Here is a screenshot

OraError.PNG

The code is very simple

using System;

using Oracle.ManagedDataAccess.Client;

using Oracle.ManagedDataAccess.Types;


namespace core_console_ora

{

   class Program

  {

   static void Main(string[] args)

  {

  Console.WriteLine("Hello World! Lets try and connect to Oracle");


   string Development_UserPass = "USer Id=u203379;Password=************;";

   string Develoment_Connect = "Data Source=dfargs03-scan:1521/GISAENTW;";


   string connectionstring = Development_UserPass + Develoment_Connect ; 

   OracleConnection con = new OracleConnection();

  con.ConnectionString = connectionstring;

  con.Open();


   OracleCommand cmd = con.CreateCommand();

  cmd.CommandText = "select user from dual" ;

   OracleDataReader reader = cmd.ExecuteReader();


   while (reader.Read())

  {

  Console.WriteLine("DB User. " + reader.GetString(0));

  }


  Console.WriteLine();

  Console.WriteLine("Press 'Enter' to continue");

  Console.ReadLine();

  }

  }

}

But errors at line 17 -  OracleConnection con = new OracleConnection();

To add Oracle Maanaged Data Access used:

dotnet add package Oracle.ManagedDataAccess --version 19.3.1

dotnet add package Oracle.ManagedDataAccess --version 19.3.1 --framework netcoreapp2.2

Changing, specifying the framework did not solve the problem

Interestingly, I have also added the extension "Oracle Developer Tools for VS Code" and this works without any problem when I use a full connection string or a connection based on TNSNames.

Can anyone tell me how to eliminate this error ...

Many thanks in advance

Update

Just did the same exercise using Visual Studio 2017

And get the following error from the same line  ...             OracleConnection con = new OracleConnection();

System.TypeInitializationException

  HResult=0x80131534

  Message=The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception.

  Source=Oracle.ManagedDataAccess

  StackTrace:

   at Oracle.ManagedDataAccess.Client.OracleConnection..ctor()

Inner Exception 1:

FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Best Answer

  • user552932
    user552932 Member Posts: 5
    edited August 2019 Accepted Answer

    Problem resolved

    A stupid error but had installed the Oracle.ManagedDataAccess package using - this is not the correct Managed Data Access Component

    dotnet add package Oracle.ManagedDataAccess --version 19.3.1

    dotnet add package Oracle.ManagedDataAccess --version 19.3.1 --framework netcoreapp2.2

    Remove the one above and install the correct one for dotnet core using

    dotnet add package Oracle.ManagedDataAccess.Core --version 2.19.31

    It is quite easy to mix the two up...

    Carlos Sampaio

Answers

  • user552932
    user552932 Member Posts: 5
    edited August 2019 Accepted Answer

    Problem resolved

    A stupid error but had installed the Oracle.ManagedDataAccess package using - this is not the correct Managed Data Access Component

    dotnet add package Oracle.ManagedDataAccess --version 19.3.1

    dotnet add package Oracle.ManagedDataAccess --version 19.3.1 --framework netcoreapp2.2

    Remove the one above and install the correct one for dotnet core using

    dotnet add package Oracle.ManagedDataAccess.Core --version 2.19.31

    It is quite easy to mix the two up...

    Carlos Sampaio
Sign In or Register to comment.