Forum Stats

  • 3,876,035 Users
  • 2,267,022 Discussions
  • 7,912,404 Comments

Discussions

ODP.NET Core error on Blazor Client. Does it work with WASM?

F.J.
F.J. Member Posts: 26 Red Ribbon

Hi, hopefully someone can confirm or help me solve this.

Steps to Repro:

  1. Create the default Blazor Client project in Visual Studio (I'm using Community 2019 16.10.0)
  2. Add the Oracle.ManagedDataAccess.Core (3.21.1) NuGet package
  3. Modify the Counter.razor file to add the code to open the Database connection. The only change to the auto-generated code is the Using clauses for the ODP and the attempt to create the OracleConnection.
@page "/counter"
@using Oracle.ManagedDataAccess.Client
@using Oracle.ManagedDataAccess.Types
 
<h1>Counter</h1>
 
<p>Current count: @currentCount</p>
 
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
 
@code {
    private int currentCount = 0;
 
    private void IncrementCount()
    {
        currentCount++;
 
        string conString = "User Id=hr;Password=hr;DAta Source=localhost:1521/orcl;";
 
         // THE ERROR HAPPENS HERE, with or without the conString as a parameter
         OracleConnection con = new  OracleConnection();

        //con.ConnectionString = conString;
        //con.Open();
        //con.Close();
    }
}

This is the error thrown as shown in the browser console:

----------------------------

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

    Unhandled exception rendering component: The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception.

System.TypeInitializationException: The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception. ---> System.InvalidOperationException: Process has exited or is inaccessible, so the requested information is not available.

 at System.Diagnostics.Process.get_ProcessName () <0x31c4300 + 0x0004a> in <filename unknown>:0

 at OracleInternal.Common.CustomConfigFileReader.GetProcessAndEnvInfo () <0x31c4120 + 0x00022> in <filename unknown>:0

 at OracleInternal.Common.CustomConfigFileReader..ctor (System.Boolean bIsManaged) <0x31c1df8 + 0x00054> in <filename unknown>:0

 at OracleInternal.Common.ConfigBaseClass.GetInstance (System.Boolean bIsManaged) <0x31c1670 + 0x0000e> in <filename unknown>:0

 at OracleInternal.Common.ProviderConfig..cctor () <0x31c1328 + 0x0003a> in <filename unknown>:0

 --- End of inner exception stack trace ---

 at Oracle.ManagedDataAccess.Client.OracleConnection..ctor () <0x319f438 + 0x0008a> in <filename unknown>:0

 at test1.wasm.notcorehosted._31.Pages.Counter.IncrementCount () <0x3166bd0 + 0x00026> in <filename unknown>:0

 at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync[T] (System.MulticastDelegate delegate, T arg) <0x31460b8 + 0x0005e> in <filename unknown>:0

 at Microsoft.AspNetCore.Components.EventCallbackWorkItem.InvokeAsync (System.Object arg) <0x3145df8 + 0x0000a> in <filename unknown>:0

 at Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync (Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, System.Object arg) <0x3145d60 + 0x0000a> in <filename unknown>:0

 at Microsoft.AspNetCore.Components.EventCallback.InvokeAsync (System.Object arg) <0x31438f0 + 0x00040> in <filename unknown>:0

 at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync (System.UInt64 eventHandlerId, Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo fieldInfo, System.EventArgs eventArgs) <0x3142ee0 + 0x000a8> in <filename unknown>:0 blazor.webassembly.js:1:38061


----------------------------


Please note:    The same steps and code work if the Blazor project is a Blazor Server project instead of Client.


Any guidance and help is greatly appreciated.


Regards

-Fernando

«1

Answers

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 3,154 Employee

    Check you ODP.NET assembly again. Make sure it's not from the Oracle.ManagedDataAccess NuGet package. That contains a similar assembly to Oracle.ManagedDataAccess.Core. But instead of ODP.NET Core, it has managed ODP.NET. Managed ODP.NET only works with .NET Framework and will look for an app/web.config file, which is what the exception suggests the provider is trying to do.

  • F.J.
    F.J. Member Posts: 26 Red Ribbon
    edited Jun 2, 2021 6:34PM

    Thank you Alex for your quick response.

    I'm afraid I'm not sure how to proceed from what you say.

    Initially I installed the ODTforVS2019_193100.zip that I downloaded from the ODT website. I guess that put the Oracle.ManagedDataAccess.dll in the folder C:\app\<myuser>\product\18.0.0\dbhomeXE\ODP.NET\managed\common.

    I then created the describied default Blazor Client project and added the Oracle.ManagedDataAccess.Core package by right-clicking on the project and selecting Manage NuGet Packages to find it and install it. This package is the same I find if I try to download the ODT.NET Core from the website: https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/

    Then I change the Counter.razor file as described to simply attempt to create a database connection using the ODT. That's when I get the error.

    If instead of adding the NuGet Package I add the reference to that DLL mentioned above, I get errors too in the exact same line of code. So I'm not sure what's wrong and how to proceed. In addition, as I said, this doesn't happen if the project I create is a Blazor Server project. This happens with a Blazor Client.


    These are the errors I get in the browser if I add the local DLL instead of the NuGet Package:

    -------

    L: Can't find custom attr constructor image: Oracle.ManagedDataAccess.dll mtoken: 0x0a00002c due to: Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. blazor.webassembly.js:1:38022


    Uncaught (in promise) Error: System.AggregateException: An error occurred while writing to logger(s). (Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.) ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. at (wrapper managed-to-native) System.MonoCustomAttrs.IsDefinedInternal(System.Reflection.ICustomAttributeProvider,System.Type) at System.MonoCustomAttrs.IsDefined (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) <0x2d542c8 + 0x00050> in <filename unknown>:0 at System.RuntimeType.IsDefined (System.Type attributeType, System.Boolean inherit) <0x2d54120 + 0x00052> in <filename unknown>:0 at System.Attribute.IsDefined (System.Reflection.MemberInfo element, System.Type attributeType, System.Boolean inherit) <0x2fde510 + 0x000d2> in <filename unknown>:0 at System.Attribute.IsDefined (System.Reflection.MemberInfo element, System.Type attributeType) <0x2fd41c0 + 0x0000a> in <filename unknown>:0 at System.Reflection.CustomAttributeExtensions.IsDefined (System.Reflection.MemberInfo element, System.Type attributeType) <0x2fd4100 + 0x00008> in <filename unknown>:0 at System.Diagnostics.StackTrace.GetFullNameForStackTrace (System.Text.StringBuilder sb, System.Reflection.MethodBase mi, System.Boolean needsNewLine, System.Boolean& skipped, System.Boolean& isAsync) <0x32532a8 + 0x000e2> in <filename unknown>:0 at System.Diagnostics.StackTrace.AddFrames (System.Text.StringBuilder sb, System.Boolean separator, System.Boolean& isAsync) <0x3252da8 + 0x0010c> in <filename unknown>:0 at System.Diagnostics.StackTrace.ToString () <0x3250718 + 0x000c8> in <filename unknown>:0 at System.Diagnostics.StackTrace.ToString (System.Diagnostics.StackTrace+TraceFormat traceFormat) <0x32505c0 + 0x00006> in <filename unknown>:0 at System.Environment.GetStackTrace (System.Exception e, System.Boolean needFileInfo) <0x3250160 + 0x0003c> in <filename unknown>:0 at System.Exception.GetStackTrace (System.Boolean needFileInfo) <0x324fef8 + 0x00058> in <filename unknown>:0 at System.Exception.ToString (System.Boolean needFileLineInfo, System.Boolean needMessage) <0x324f8c0 + 0x000d4> in <filename unknown>:0 at System.Exception.ToString () <0x324f808 + 0x00006> in <filename unknown>:0 at Microsoft.AspNetCore.Components.WebAssembly.Services.WebAssemblyConsoleLogger`1[T].CreateDefaultLogMessage (System.Text.StringBuilder logBuilder, Microsoft.Extensions.Logging.LogLevel logLevel, System.String logName, System.Int32 eventId, System.String message, System.Exception exception) <0x324eb38 + 0x00134> in <filename unknown>:0 at Microsoft.AspNetCore.Components.WebAssembly.Services.WebAssemblyConsoleLogger`1[T].WriteMessage (Microsoft.Extensions.Logging.LogLevel logLevel, System.String logName, System.Int32 eventId, System.String message, System.Exception exception) <0x3247db8 + 0x0003c> in <filename unknown>:0 at Microsoft.AspNetCore.Components.WebAssembly.Services.WebAssemblyConsoleLogger`1[T].Log[TState] (Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception exception, System.Func`3[T1,T2,TResult] formatter) <0x3247450 + 0x0007a> in <filename unknown>:0 at Microsoft.Extensions.Logging.Logger.<Log>g__LoggerLog|12_0[TState] (Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, Microsoft.Extensions.Logging.ILogger logger, System.Exception exception, System.Func`3[T1,T2,TResult] formatter, System.Collections.Generic.List`1[System.Exception]& exceptions, TState& state) <0x3247238 + 0x00026> in <filename unknown>:0 --- End of inner exception stack trace --- at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x2ab91c0 + 0x000ce> in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously (Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo& callInfo, Microsoft.JSInterop.Infrastructure.IDotNetObjectReference objectReference, System.String argsJson) <0x3123f28 + 0x00180> in <filename unknown>:0 at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet (Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo invocationInfo, System.String argsJson) <0x3123af0 + 0x00092> in <filename unknown>:0 ---> (Inner Exception #0) System.IO.FileNotFoundException: Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. File name: 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at (wrapper managed-to-native) System.MonoCustomAttrs.IsDefinedInternal(System.Reflection.ICustomAttributeProvider,System.Type) at System.MonoCustomAttrs.IsDefined (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) <0x2d542c8 + 0x00050> in <filename unknown>:0 at System.RuntimeType.IsDefined (System.Type attributeType, System.Boolean inherit) <0x2d54120 + 0x00052> in <filename unknown>:0 at System.Attribute.IsDefined (System.Reflection.MemberInfo element, System.Type attributeType, System.Boolean inherit) <0x2fde510 + 0x000d2> in <filename unknown>:0 at System.Attribute.IsDefined (System.Reflection.MemberInfo element, System.Type attributeType) <0x2fd41c0 + 0x0000a> in <filename unknown>:0 at System.Reflection.CustomAttributeExtensions.IsDefined (System.Reflection.MemberInfo element, System.Type attributeType) <0x2fd4100 + 0x00008> in <filename unknown>:0 at System.Diagnostics.StackTrace.GetFullNameForStackTrace (System.Text.StringBuilder sb, System.Reflection.MethodBase mi, System.Boolean needsNewLine, System.Boolean& skipped, System.Boolean& isAsync) <0x32532a8 + 0x000e2> in <filename unknown>:0 at System.Diagnostics.StackTrace.AddFrames (System.Text.StringBuilder sb, System.Boolean separator, System.Boolean& isAsync) <0x3252da8 + 0x0010c> in <filename unknown>:0 at System.Diagnostics.StackTrace.ToString () <0x3250718 + 0x000c8> in <filename unknown>:0 at System.Diagnostics.StackTrace.ToString (System.Diagnostics.StackTrace+TraceFormat traceFormat) <0x32505c0 + 0x00006> in <filename unknown>:0 at System.Environment.GetStackTrace (System.Exception e, System.Boolean needFileInfo) <0x3250160 + 0x0003c> in <filename unknown>:0 at System.Exception.GetStackTrace (System.Boolean needFileInfo) <0x324fef8 + 0x00058> in <filename unknown>:0 at System.Exception.ToString (System.Boolean needFileLineInfo, System.Boolean needMessage) <0x324f8c0 + 0x000d4> in <filename unknown>:0 at System.Exception.ToString () <0x324f808 + 0x00006> in <filename unknown>:0 at Microsoft.AspNetCore.Components.WebAssembly.Services.WebAssemblyConsoleLogger`1[T].CreateDefaultLogMessage (System.Text.StringBuilder logBuilder, Microsoft.Extensions.Logging.LogLevel logLevel, System.String logName, System.Int32 eventId, System.String message, System.Exception exception) <0x324eb38 + 0x00134> in <filename unknown>:0 at Microsoft.AspNetCore.Components.WebAssembly.Services.WebAssemblyConsoleLogger`1[T].WriteMessage (Microsoft.Extensions.Logging.LogLevel logLevel, System.String logName, System.Int32 eventId, System.String message, System.Exception exception) <0x3247db8 + 0x0003c> in <filename unknown>:0 at Microsoft.AspNetCore.Components.WebAssembly.Services.WebAssemblyConsoleLogger`1[T].Log[TState] (Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, System.Exception exception, System.Func`3[T1,T2,TResult] formatter) <0x3247450 + 0x0007a> in <filename unknown>:0 at Microsoft.Extensions.Logging.Logger.<Log>g__LoggerLog|12_0[TState] (Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, Microsoft.Extensions.Logging.ILogger logger, System.Exception exception, System.Func`3[T1,T2,TResult] formatter, System.Collections.Generic.List`1[System.Exception]& exceptions, TState& state) <0x3247238 + 0x00026> in <filename unknown>:0 <---

        endInvokeDotNetFromJS https://localhost:44310/_framework/blazor.webassembly.js:1

        invokeJSFromDotNet https://localhost:44310/_framework/blazor.webassembly.js:1

        _mono_wasm_invoke_js_marshalled https://localhost:44310/_framework/wasm/dotnet.3.2.0.js:1

        _mono_wasm_invoke_method https://localhost:44310/_framework/wasm/dotnet.3.2.0.js:1

        call_method https://localhost:44310/_framework/wasm/dotnet.3.2.0.js:1

        bind_static_method https://localhost:44310/_framework/wasm/dotnet.3.2.0.js:1

        beginInvokeDotNetFromJS https://localhost:44310/_framework/blazor.webassembly.js:1

        s https://localhost:44310/_framework/blazor.webassembly.js:1

        invokeMethodAsync https://localhost:44310/_framework/blazor.webassembly.js:1

        v https://localhost:44310/_framework/blazor.webassembly.js:1

        dispatchEvent https://localhost:44310/_framework/blazor.webassembly.js:1

        eventDelegator https://localhost:44310/_framework/blazor.webassembly.js:1

        eventDelegator https://localhost:44310/_framework/blazor.webassembly.js:1

        onGlobalEvent https://localhost:44310/_framework/blazor.webassembly.js:1

    blazor.webassembly.js:1:10049


    -------


    Thank you for your help

    -Fernando

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 3,154 Employee

    Ok, I think the reason behind your error is that you used ODT to create the DB connection that you use. ODT uses either managed ODP.NET or unmanaged ODP.NET for its DB connectivity. It doesn't use ODP.NET Core yet. When ODT generates code ADO.NET code, it generates managed ODP.NET code.

    In your case, managed ODP.NET is being used. Is there a way you can re-create the DB connection without ODT? That will ensure you use ODP.NET Core for the connection.

  • F.J.
    F.J. Member Posts: 26 Red Ribbon

    "Is there a way you can re-create the DB connection without ODT? That will ensure you use ODP.NET Core for the connection."

    Well, that would be my question for you :) I don't know.

    I tried removing and re-adding (as well as modifying) the Data Connection in Visual Studio Server Explorer\Data connections but the only ODP.NET Data Provider that appears in there under Oracle Database is "Oracle Database (ODP.NET, Managed Driver)". Nevertheless, even if I delete that connection there I can still run the application and get the same error as well as it works with the other projects (Console App and Blazor-Server), so there's no difference regarding those connections there, they seem to be used for having access to the Database within Visual Studio. The problem in that case could the Data Provider that is available, I don't know.


    So, Why does that same connection work in a Console Application and in a Blazor-Server Application, but not in a Blazor-Client?

    and, How should I have created the connection in the first place to ensure ODP.NET Core was used?


    I find this to be a very common and simple scenario: "Blazor-Client default app + ODP.NET Core DB Connection" to have this problems :(


    I really appreciate all your help.

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 3,154 Employee
    edited Jun 4, 2021 9:16PM

    Sorry, when you wrote ODT, I thought you were referencing Oracle Developer Tools, which auto-generates ODP.NET code. I was confused by that typo. When I re-read your posits, it doesn't sound like any ODP.NET code was auto-generated. Just Blazor code is.

    Do you happen to be running Blazor on .NET Framework? There are some ways for managed ODP.NET to be pulled into an app in .NET Framework, such as when it's been GACed. But this would only be possible in .NET FW, but not .NET Core.

    I tried repeating your Blazor setup steps. When I run the app, it never runs the Counter.razor code. I added the same code to the Program.cs, but it never ran either. I'm not familiar with Blazor. So, I'm not sure what it's actually trying to run.

  • F.J.
    F.J. Member Posts: 26 Red Ribbon

    Hi Alex,

    I'm not changing anything on the default blazor project to make it run on .NET Framework. It runs a .NET Core as you specified when you create the project with the wizard.

    The reason you are not seeing the Counter increase when clicking on the button is because the attempt to create the database connection makes the whole method fail (see steps 6 and 7 below). Please follow these more detailed steps to create the simple default project with the ODP included:


    1. Add a New Blazor Web Assembly Project, Target Framework = .NET Core 3.1

    2. Run default project to confirm it runs ok (Select Counter and button Click-me, Current Counter should increase)

    3. Add Oracle.ManagedDataAccess.Core NuGet package to the project

    4. Open Counter.razor file and replace the whole code with this, which includes references to the ODP.NET and attempts the Database Connection when the button "Click-me" is pressed.


    @page "/counter"

    @using Oracle.ManagedDataAccess.Client

    @using Oracle.ManagedDataAccess.Types


    <h1>CounterY</h1>

    <p>Current count: @currentCount</p>


    <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

    @code {

       private int currentCount = 0;

       private void IncrementCount()

       {

           currentCount++;

           string conString = string.Format("User Id=hr;Password=hr;DAta Source=localhost:1521/xepdb1;");

           OracleConnection con = new OracleConnection();

           //con.ConnectionString = conString;

           //con.Open();

           //con.Close();

       }

    }


    5. Run the project

    6. Before clicking on the Counter button, open the Browser Developer tools and ensure the Console tab is shown.

    7. Click the "Click me" button. The errors are shown in the browser console.

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 3,154 Employee

    I tried running your test case on another computer and was finally able to reproduce the issue you see. I filed Bug 32967929 so that one of my dev team members can review.

    One thing I noticed is that the Web Assembly project target framework becomes .NET Standard 2.1 despite having chosen .NET Core 3.1. The Blazor Server project will use .NET Core as the target framework. That may have something to do with the bug.

  • F.J.
    F.J. Member Posts: 26 Red Ribbon

    Hi Alex,

    Good to hear that you were able to reproduce it and file the bug.

    Where can I follow the progress of the bug?

    And yes, I also notice what you mention about the different target frameworks for Web Assembly and Server blazor projects. After some research I found that's the expected behavior. I hope your team can find the problem and solution.

    Regards

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 3,154 Employee

    You can follow the bug progress if your DBA gives you access to your organization's My Oracle Support account.

    https://support.oracle.com/portal/

  • F.J.
    F.J. Member Posts: 26 Red Ribbon

    Hello Alex,

    Any update from you on this? The bug hasn't had any update since it was first filed a month ago :(


    Regards