我是C#的新手。
我编写了一个C#控制台应用程序,它使用ODP通过Oracle.DataAccess.Client命名空间连接Oracle数据库。我的开发机器使用的是Oracle.DataAccess ver 2.112.2.0,开发服务器也使用Oracle.DataAccess ver 2.112.2.0,程序运行正常。使用更高版本的Oracle.DataAccess ver 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
当我尝试在我的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)
答案 0 :(得分: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>