How to debug and fix "Exception was chosen as the target of the call" for EF 6, Oracle DB, Controller Scaffolding

Edit 2:

This does not happen when I use SQL Server. This only happens when I use Oracle. It was suggested to debug or provide an internal exception for this. However, since this exception occurs during scaffolding, I cannot get an internal exception. In addition, I’m not sure if the process of scaffolding construction can be debugged. If there is anyone who knows how to do this, let me know.


Mistake

An error occurred while starting the code generator:

'Exception selected by call target

Well, firstly, the search results error seems to return .

And so I found out that this error is not exceptional for creation Controller scaffoldingin EF 6.

But my case is when I am going to create Controller scaffoldingusing EF 6 in VS2013 when I create MVC web application.

enter image description here

The option I'm using:

MVC 5 Controller with views, using Entity Framework

I use Oracle Databaseand Oracle.ManagedDataAccess namespace. Some relevant posts I found are as follows:

But none of them speaks of a specific case for Oracle DB

DB , , :

  • sections, connectionStrings providers , :

    <configSections>
      <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </configSections>
    
    <connectionStrings>
      <add name="EmployeeContext" connectionString="metadata=res://*/Models.EmployeeDataModel.csdl|res://*/Models.EmployeeDataModel.ssdl|res://*/Models.EmployeeDataModel.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;DATA SOURCE=VSDB;PASSWORD=mypassword;USER ID=myuser&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
    
    <providers>
      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </providers>
    
  • DbSet Context IDBSet

    public virtual DbSet<Employee> Employees1 { get; set; }
    
  • VS2013 with update 5.

  • Entity Framework 6.1.3
  • defaultConnectionFactory :

    <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameters>
            <parameter value="mssqllocaldb" />
        </parameters>
      </defaultConnectionFactory>
    </entityFramework>
    

    <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameters>
            <parameter value="v11.0" />
        </parameters>
      </defaultConnectionFactory>
    </entityFramework>
    
  • OnModelCreating :

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        throw new UnintentionalCodeFirstException();
    }
    

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        base.OnModelCreating(modelBuilder);
        modelBuilder.HasDefaultSchema("myschema");
    }
    

. . , .

, . ?

Edit:

, - , "" , , . -, Entity , , .

2:

, SQL-, Steve , Squiggle chat, . , - Oracle DB () ODP.Net, Oracle.ManagedDataAccess - EF.

+4
2

,

" , - , " ", , ."

- .net Global.asax, .

, customErrors Off Web.config .

Application_Error Global.asax, :

void Application_Error(object sender, EventArgs e)
{ ... }

MSDN:

void Application_Error(object sender, EventArgs e)
{
  // Code that runs when an unhandled error occurs

  // Get the exception object.
  Exception exc = Server.GetLastError();

  // Handle HTTP errors
  if (exc.GetType() == typeof(HttpException))
  {
    // The Complete Error Handling Example generates
    // some errors using URLs with "NoCatch" in them;
    // ignore these here to simulate what would happen
    // if a global.asax handler were not implemented.
      if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
      return;

    //Redirect HTTP errors to HttpError page
    Server.Transfer("HttpErrorPage.aspx");
  }

  // For other kinds of errors give the user some information
  // but stay on the default page
  Response.Write("<h2>Global Page Error</h2>\n");
  Response.Write(
      "<p>" + exc.Message + "</p>\n");
  Response.Write("Return to the <a href='Default.aspx'>" +
      "Default Page</a>\n");

  // Log the exception and notify system operators
  ExceptionUtility.LogException(exc, "DefaultPage");
  ExceptionUtility.NotifySystemOps(exc);

  // Clear the error from the server
  Server.ClearError();
}

/ . , .

+2

- , : , ..

, , Oracle, , machine.config, .

machine.config, , .

:

  • EF 6 Nuget
  • Oracle.ManagedDataAccess v12.2.1100
  • Oracle.ManagedDataAccess.EntiyFramework v12.2.1100

machine.config:

<!-- <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" /> -->
<!-- <oracle.manageddataaccess.client> -->
    <!-- <version number="4.122.1.0"> -->
      <!-- <settings> -->
        <!-- <setting name="tns_admin" value="c:\oracle64\client\laralal\product\12.2.0\client_1\network\admin" /> -->
      <!-- </settings> -->
    <!-- </version> -->
  <!-- </oracle.manageddataaccess.client> -->
0

Source: https://habr.com/ru/post/1629497/


All Articles