2

我是 C# 新手。

我编写了一个 C# 控制台应用程序,它使用 ODP 使用 Oracle.DataAccess.Client 命名空间连接 Oracle 数据库。我的开发机器使用 Oracle.DataAccess 2.112.2.0 版,开发服务器也使用 Oracle.DataAccess 2.112.2.0 版,程序运行良好。使用更高版本的 Oracle.DataAccess 版本 2.112.3.0 的 prod 服务器并且程序无法运行,我得到以下异常。

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Oracle.DataAccess, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f
429c47342' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Oracle.DataAccess, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342'
   at OPSegmentTDs.Programu.Main(String[] args)


I tried installing ODAC for Oracle client 11.2.0.3.0 on my dev machine and added the higher ver of Oracle.DataAccess reference 2.112.3.0 in my application and when I built it I got this warning but the program built successfully.

Consider app.config remapping of assembly "Oracle.DataAccess, Culture=neutral, PublicKeyToken=89b483f429c47342" from Version "2.112.2.0" [] to Version "2.112.3.0" [C:\Oracle\OraODP1123\product\11.2.0\client_2\ODP.NET\bin\2.x\Oracle.DataAccess.dll] to solve conflict and get rid of warning.
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets : warning MSB3247: Found conflicts between different versions of the same dependent assembly.
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /platform:AnyCPU /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\Work\Build\GOLD\GIS2002\GISLib\bin\Debug\GIS.dll /reference:C:\Work\Build\09072012\Linde.Niche.DB\bin\Debug\Linde.Niche.DB.dll /reference:C:\Work\Build\09072012\Linde.Niche.DB.OP\bin\Debug\Linde.Niche.DB.OP.dll /reference:C:\Work\Build\09072012\Linde.Niche\bin\Debug\Linde.Niche.dll /reference:C:\Work\Build\09072012\OPLib\OPLib\bin\Debug\OPLib.dll /reference:C:\Oracle\OraODP1123\product\11.2.0\client_2\ODP.NET\bin\2.x\Oracle.DataAccess.dll /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\OPSegmentTDs.exe /target:exe Program.cs Properties\AssemblyInfo.cs

当我尝试在我的产品服务器上运行新版本时,应用程序崩溃并出现相同的错误

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Oracle.DataAccess, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f
429c47342' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Oracle.DataAccess, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342'
   at OPSegmentTDs.Programu.Main(String[] args)
4

1 回答 1

1

尝试在应用程序的 bin/setup 文件夹下复制正确版本的 Oracle DLL(来自 ODAC112030Xcopy_32bit.zip 或 ODAC112030Xcopy_x64.zip),并将以下内容添加到应用程序的 app.config 中:

<system.data>
    <DbProviderFactories>
        <remove invariant="Oracle.DataAccess.Client" />
        <add name="Oracle Data Provider for .NET"
            invariant="Oracle.DataAccess.Client"
            description="Oracle Data Provider for .NET"
            type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </DbProviderFactories>
</system.data>
于 2012-12-05T13:46:36.177 回答