C# 无法加载文件或程序集';Oracle.ManagedDataAccess.EntityFramework

C# 无法加载文件或程序集';Oracle.ManagedDataAccess.EntityFramework,c#,asp.net,.net,oracle,entity-framework,C#,Asp.net,.net,Oracle,Entity Framework,当我想启动我的asp.net web应用程序时出现此错误 The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) ... Line 22: { Line 23: public ApplicationDbContext() Line 24: : base("DefaultConnection", throwIfV1Schema: f

当我想启动我的asp.net web应用程序时出现此错误

The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) 
...

Line 22:     {
Line 23:         public ApplicationDbContext()
Line 24:             : base("DefaultConnection", throwIfV1Schema: false)
Line 25:         {
Line 26:         }
它的MVC web应用程序连接到oracle数据库,我在NuGet上使用了EntinyFramework 6.1.3

我使用的是64位windows 7, 五、2015演播室 和32位ODAC 12c版本4

我尝试在Visual studio中设置为从x64或x86开始,但没有帮助

请给我一些建议。多谢各位

代码隐藏: Web.config:

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="Oracle.ManagedDataAccess.Client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.12.1.0.2.4, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <sectionGroup name="devExpress">
      <section name="themes" type="DevExpress.Web.ThemesConfigurationSection, DevExpress.Web.v16.1, Version=16.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="compression" type="DevExpress.Web.CompressionConfigurationSection, DevExpress.Web.v16.1, Version=16.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="settings" type="DevExpress.Web.SettingsConfigurationSection, DevExpress.Web.v16.1, Version=16.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
      <section name="errors" type="DevExpress.Web.ErrorsConfigurationSection, DevExpress.Web.v16.1, Version=16.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20160811110342.mdf;Initial Catalog=aspnet-WebApplication1-20160811110342;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    <add name="Model1" connectionString="DATA SOURCE=XXXXX;PERSIST SECURITY INFO=True;USER ID=XXXX"
      providerName="Oracle.ManagedDataAccess.Client"/>
    <add name="xpf.printing" connectionString="xpoprovider=MSSqlServer;data source=(localdb)\mssqllocaldb;attachdbfilename=|DataDirectory|\ReportService.mdf;integrated security=True;connect timeout=120" />
  </connectionStrings>
  ....
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=4.12.1.0.2.4, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  ....
</configuration>

....
....
IdentityModels.cs:

using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;

namespace WebApplication1.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }
}
使用System.Data.Entity;
使用System.Security.Claims;
使用System.Threading.Tasks;
使用Microsoft.AspNet.Identity;
使用Microsoft.AspNet.Identity.EntityFramework;
命名空间WebApplication1.Models
{
//您可以通过向ApplicationUser类添加更多属性来为用户添加配置文件数据,请访问http://go.microsoft.com/fwlink/?LinkID=317594 了解更多。
公共类应用程序用户:IdentityUser
{
公共异步任务GenerateUserIdentityAsync(用户管理器)
{
//注意authenticationType必须与CookieAuthenticationOptions.authenticationType中定义的类型匹配
var userIdentity=wait manager.CreateIdentityAsync(这是DefaultAuthenticationTypes.ApplicationOkie);
//在此处添加自定义用户声明
返回用户身份;
}
}
公共类ApplicationDbContext:IdentityDbContext
{
公共应用程序上下文()
:base(“DefaultConnection”,throwifvv1schema:false)
{
}
公共静态应用程序上下文创建()
{
返回新的ApplicationDbContext();
}
}
}

我也有同样的错误,我被这样修复了: 您需要更改web.config,如下所示:

<entityFramework>
  <defaultConnectionFactory type="Oracle.ManagedDataAccess.EntityFramework.OracleConnectionFactory, Oracle.ManagedDataAccess.EntityFramework"></defaultConnectionFactory>
  <providers>
    <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
</entityFramework>

您需要安装entityFramework 1.安装程序包EntityFramework-版本6.1.1 2.添加链接设置ODAC 12c版本4中的参考 Oracle.ManagedDataAccess.EntityFramework.dll 将Oracle.ManagedDataAccess.dll添加到项目中。
将完成

您应该从Oracle站点下载32bit Oracle.DataClient,并将项目设置为x86。64位客户端版本存在已知问题/错误,它将使用32bit
Oracle.DataAccess.client在64位操作系统上工作我每天都处理这个问题,并且在添加引用时设置CopyLocal=true属性将dll复制到依赖项文件夹中。如何添加这些引用?nuget?我发布了更多关于我问题的信息@MethodMan:我正在使用32位Oracle.DataClient。。。不了解你关于dll,从何处到何处复制和什么参考??谢谢。如果您不熟悉如何添加引用以及如何设置单个引用的属性,那么您将无法解决您的问题。。很抱歉