让人蛋疼的“Oracle.DataAccess.dll”

项目介绍:为前台网站提供rest接口来操作erp相关数据

涉及db:oracle11

技术方案:因为erp是用remoting来调用,我想rest实现部分调用remoting来操作减少耦合,当然性能上损失点。

可惜架构师要求直接引用dll来调用

言归正传,当初erp是用32位oracle客户端而我们机器都是装64位系统,所以编译时候必须用x86来,不然启动会报"未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。" ,后来在我的建议下换成64位客户端用anycpu编译就可以了。

rest服务调用erp的接口需要引用Oracle.DataAccess.dll版本为4.112.3.0,先用iishost服务来测试调用,wcf测试客户端一直报错

错误: 无法从 http://localhost:8733/MallAPI/SaleOrderService.svc 获取元数据如果是您有权访问的 Windows (R) Communication Foundation 服务,请检查是否已启用在指定地址发布元数据。有关启用元数据发布的帮助,请参阅 http://go.microsoft.com/fwlink/?LinkId=65455 上的 MSDN 文档。WS-Metadata Exchange 错误    URI: http://localhost:8733/MallAPI/SaleOrderService.svc    元数据包含无法解析的引用:“http://localhost:8733/MallAPI/SaleOrderService.svc”。    接收对 http://localhost:8733/MallAPI/SaleOrderService.svc 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。有关详细信息,请参见服务器日志。    基础连接已经关闭: 接收时发生错误。    无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。    远程主机强迫关闭了一个现有的连接。HTTP GET Error    URI: http://localhost:8733/MallAPI/SaleOrderService.svc    下载“http://localhost:8733/MallAPI/SaleOrderService.svc”时出错。    请求失败,错误信息为:--<!DOCTYPE html><html>    <head>        <title>未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。</title>        <meta name="viewport" content="width=device-width" />        <style>         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}          p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}         .marker {font-weight: bold; color: black;text-decoration: none;}         .version {color: gray;}         .error {margin-bottom: 10px;}         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }         @media screen and (max- 639px) {          pre {  440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }         }         @media screen and (max- 479px) {          pre {  280px; }         }        </style>    </head>    <body bgcolor="white">            <span><H1>“/MallAPI”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1>            <h2> <i>未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。</i> </h2></span>            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">            <b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。            <br><br>            <b> 异常详细信息: </b>System.BadImageFormatException: 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。<br><br>            <b>源错误:</b> <br><br>            <table width=100% bgcolor="#ffffcc">               <tr>                  <td>                      <code>执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code>                  </td>               </tr>            </table>            <br>            <b>程序集加载跟踪:</b> 下列信息有助于确定程序集“Oracle.DataAccess”未能加载的原因。<br><br>            <table width=100% bgcolor="#ffffcc">               <tr>                  <td>                      <code><pre>=== 预绑定状态信息 ===日志: 用户 = huangjunhj日志: DisplayName = Oracle.DataAccess (Partial)警告: 为程序集提供了部分绑定信息:警告: 程序集名称: Oracle.DataAccess | 域 ID: 4警告: 当仅提供程序集显示名称的一部分时,将发生部分绑定。警告: 这可能导致联编程序加载错误的程序集。警告: 建议为程序集提供完全指定的文字标识,警告: 并由简单名称、版本、区域性和公钥标记组成。警告: 有关此问题的详细信息和常见解决方案,请参见白皮书 http://go.microsoft.com/fwlink/?LinkId=109270。日志: Appbase = file:///F:/work/SourceCode/MallAPI/IISHost/日志: 初始 PrivatePath = F:workSourceCodeMallAPIIISHostin调用程序集: (Unknown)。===日志: 此绑定从 default 加载上下文开始。日志: 正在使用应用程序配置文件: F:workSourceCodeMallAPIIISHostweb.config日志: 使用主机配置文件: 日志: 使用 C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config 的计算机配置文件。日志: 此时没有为引用应用策略(私有、自定义、分部或基于位置的程序集绑定)。日志: 尝试下载新的 URL file:///C:/Users/hj/AppData/Local/Temp/Temporary ASP.NET Files/mallapi/b831d71b/68b495b/Oracle.DataAccess.DLL。日志: 尝试下载新的 URL file:///C:/Users/hj/AppData/Local/Temp/Temporary ASP.NET Files/mallapi/b831d71b/68b495b/Oracle.DataAccess/Oracle.DataAccess.DLL。日志: 尝试下载新的 URL file:///F:/work/SourceCode/MallAPI/IISHost/bin/Oracle.DataAccess.DLL。错误: 未能完成程序集的安装(hr = 0x8007000b)。探测终止。</pre></code>                  </td>               </tr>            </table>            <br>            <b>堆栈跟踪:</b> <br><br>            <table width=100% bgcolor="#ffffcc">               <tr>                  <td>                      <code><pre>[BadImageFormatException: 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。]   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16   System.Reflection.Assembly.Load(String assemblyString) +28   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38[ConfigurationErrorsException: 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。]   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +258   System.Web.Compilation.BuildManager.ExecutePreAppStart() +135   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516[HttpException (0x80004005): 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。]   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874568   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456</pre></code>                  </td>               </tr>            </table>            <br>            <hr width=100% size=1 color=silver>            <b>版本信息:</b>?Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.18045            </font>    </body></html><!-- [BadImageFormatException]: 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。   在 System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)   在 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)   在 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)   在 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)   在 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)   在 System.Reflection.Assembly.Load(String assemblyString)   在 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)[ConfigurationErrorsException]: 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。   在 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)   在 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()   在 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)   在 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)   在 System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()   在 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath)   在 System.Web.Compilation.BuildManager.ExecutePreAppStart()   在 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)[HttpException]: 未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。   在 System.Web.HttpRuntime.FirstRequestInit(HttpContext context)   在 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)   在 System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)-->--.

然后我试了selfhost是ok的,我对测试客户端还不死心网上查资料,解决方案以anycpu、mixed platforms、x64编译生成都不行,来回折腾了2天,最后试了用iis来host结果是ok的,看样子wcf测试客户端默认是32位编译,当然我没有考证过,如果有哪位知道的同学麻烦告诉一下,这里先谢谢啦

结论:系统64、oracle client64如果用wcf测试客户端报错就用iis host

原文地址:https://www.cnblogs.com/hj4444/p/3304822.html