This one is close to making my head explode. I have 2 projects published to the same web server. They are developed on the same work station. I use the exact same dll reference for Oracle.DataAccess.dll. My web.config file is close to identical. The
initial code accessing Oracle is very similar. One works and the other doesn't. I'm totally stumped!
Here is the relevant source for both;
Working one:
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.Data
'***********************************************************************************************
Public Class ServMetRemDB
Implements IDisposable
Public IsDisposed As Boolean = False
Dim cn As Oracle.DataAccess.Client.OracleConnection
Dim ds As New DataSet
Dim da As OracleDataAdapter
Public Sub New()
cn = New OracleConnection("Data Source=" & sDataBase & ";User Id=" & HttpContext.Current.Session("UserID") & ";Password=" & HttpContext.Current.Session("Password") & ";")
End Sub 'New
Public Function GetServMetRemRecs(ByVal sSql As String) As DataSet
'get Service/Meter Removal record(s) (or the structure)
da = New OracleDataAdapter(sSql, cn)
Dim ocb As New Oracle.DataAccess.Client.OracleCommandBuilder(da)
da.Fill(ds, "ServMetRemRecs")
Return ds
End Function 'GetServMetRemRecs
Public Sub UpdateServMetRemRecs(ByVal ds As DataSet)
'this function inserts/updates/deletes the Service/Meter Removal record(s)
da.Update(ds.Tables("ServMetRemRecs"))
ds.Tables("ServMetRemRecs").AcceptChanges()
End Sub 'UpdateServMetRemRecs
Public Function GetMaxRecNum() As String
'get the latest Record Number key
Dim sMaxRecNum As String
Dim sSql As String
sSql = "SELECT MAX(REC_NUM_PK) FROM MIS.SOMC_SERVICE_METER_REMOVAL_TBL"
Dim cmd As New OracleCommand(sSql, cn)
Dim rdr As OracleDataReader
cn.Open()
rdr = cmd.ExecuteReader()
While rdr.Read()
If rdr(0).ToString = "" Then
sMaxRecNum = ""
Else
sMaxRecNum = rdr(0).ToString
End If
cn.Close()
Return sMaxRecNum
End While
Return Nothing
End Function 'GetMaxRecNum
Public Sub Dispose() Implements System.IDisposable.Dispose
If IsDisposed = False Then
cn.Close()
GC.SuppressFinalize(Me)
IsDisposed = True
End If
End Sub 'Dispose
Protected Overrides Sub Finalize()
MyBase.Finalize()
Dispose()
Public Class AddressDB
Implements IDisposable
Public IsDisposed As Boolean = False
Dim cn As Oracle.DataAccess.Client.OracleConnection
Dim da As OracleDataAdapter
Sub New(ByVal UserId As String, ByVal Password As String)
' ********************************************************************************************
' ** If the session variables have timed-out, send the user back to the login screen. **
' ********************************************************************************************
If UserId Is Nothing _
Or Password Is Nothing Then
HttpContext.Current.Response.Redirect("Default.aspx")
End If
cn = New Oracle.DataAccess.Client.OracleConnection("Data Source=" & sIntDB & "; User Id=" & UserId & "; Password=" & Password & "; Pooling=False;")
End Sub
Public Function AddressLookup(ByVal sStreetNum As String) As DataSet
da = New OracleDataAdapter("Select Distinct SERVICE_ADDRESS From APP_CMDS.SERVICE_ADDRESS_VIEW Where SERVICE_ADDRESS Like '" & UCase(sStreetNum) & "%' And RowNum <= 10", cn)
Dim ds As New DataSet
Dim ocb As New OracleCommandBuilder(da)
da.Fill(ds)
Return ds
End Function
Public Sub Dispose() Implements IDisposable.Dispose
If IsDisposed = False Then
cn.Close()
GC.SuppressFinalize(Me)
IsDisposed = True
End If
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
Dispose()
End Sub
End Class
Description:
An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30560: 'OracleConnection' is ambiguous in the namespace 'Oracle.DataAccess.Client'.
Source Error:
Line 6: Implements IDisposable
Line 7: Public IsDisposed As Boolean = False
Line 8: Dim cn As Oracle.DataAccess.Client.OracleConnection Line 9: Dim da As OracleDataAdapter
Line 10:
Server Error in '/applications/_laser' Application.
Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Oracle.DataAccess' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +567
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +192
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +123
[ConfigurationErrorsException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11554224
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +485
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +79
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +337
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167
[HttpException (0x80004005): Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11686928
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4863749
Apparently it is something with the web.config file. I deleted the web.config that didn't work and copied over the one that did and now the "broken" project works fine. Unfortunately when I create a new project the web.config is bad so I have to copy in
an old one.
One thing I noticed is the utf-16 encoding in the web.config that works. I also notice that even though I'm setting my Oracle reference to C:\app\oracle\product\11.2.0.2\odac32\odp.net\bin\2.x\Oracle.DataAccess.dll, the assemblies section has this; <add
assembly="Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
I'm not marking this answered until I figure out why things are this way.
kraznodar
Contributor
3332 Points
881 Posts
Compiler Error Message: BC30560: 'OracleConnection' is ambiguous in the namespace 'Oracle.DataAcc...
Jun 01, 2012 04:07 PM|LINK
This one is close to making my head explode. I have 2 projects published to the same web server. They are developed on the same work station. I use the exact same dll reference for Oracle.DataAccess.dll. My web.config file is close to identical. The initial code accessing Oracle is very similar. One works and the other doesn't. I'm totally stumped!
Here is the relevant source for both;
Working one:
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.Data
'***********************************************************************************************
Public Class ServMetRemDB
Implements IDisposable
Public IsDisposed As Boolean = False
Dim cn As Oracle.DataAccess.Client.OracleConnection
Dim ds As New DataSet
Dim da As OracleDataAdapter
Public Sub New()
cn = New OracleConnection("Data Source=" & sDataBase & ";User Id=" & HttpContext.Current.Session("UserID") & ";Password=" & HttpContext.Current.Session("Password") & ";")
End Sub 'New
Public Function GetServMetRemRecs(ByVal sSql As String) As DataSet
'get Service/Meter Removal record(s) (or the structure)
da = New OracleDataAdapter(sSql, cn)
Dim ocb As New Oracle.DataAccess.Client.OracleCommandBuilder(da)
da.Fill(ds, "ServMetRemRecs")
Return ds
End Function 'GetServMetRemRecs
Public Sub UpdateServMetRemRecs(ByVal ds As DataSet)
'this function inserts/updates/deletes the Service/Meter Removal record(s)
da.Update(ds.Tables("ServMetRemRecs"))
ds.Tables("ServMetRemRecs").AcceptChanges()
End Sub 'UpdateServMetRemRecs
Public Function GetMaxRecNum() As String
'get the latest Record Number key
Dim sMaxRecNum As String
Dim sSql As String
sSql = "SELECT MAX(REC_NUM_PK) FROM MIS.SOMC_SERVICE_METER_REMOVAL_TBL"
Dim cmd As New OracleCommand(sSql, cn)
Dim rdr As OracleDataReader
cn.Open()
rdr = cmd.ExecuteReader()
While rdr.Read()
If rdr(0).ToString = "" Then
sMaxRecNum = ""
Else
sMaxRecNum = rdr(0).ToString
End If
cn.Close()
Return sMaxRecNum
End While
Return Nothing
End Function 'GetMaxRecNum
Public Sub Dispose() Implements System.IDisposable.Dispose
If IsDisposed = False Then
cn.Close()
GC.SuppressFinalize(Me)
IsDisposed = True
End If
End Sub 'Dispose
Protected Overrides Sub Finalize()
MyBase.Finalize()
Dispose()
End Sub 'Finalize
End Class 'ServMetRemDB
'***********************************************************************************************
### web.config ####
<?xml version="1.0" encoding="utf-16" ?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
<assemblies>
<add assembly="Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Generic"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Linq"/>
<add namespace="System.Xml.Linq"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
</pages>
<authentication mode="Windows"/>
</system.web>
</configuration>
'***********************************************************************************************
#################################################################################################
The one that fails:
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.Data
Public Class AddressDB
Implements IDisposable
Public IsDisposed As Boolean = False
Dim cn As Oracle.DataAccess.Client.OracleConnection
Dim da As OracleDataAdapter
Sub New(ByVal UserId As String, ByVal Password As String)
' ********************************************************************************************
' ** If the session variables have timed-out, send the user back to the login screen. **
' ********************************************************************************************
If UserId Is Nothing _
Or Password Is Nothing Then
HttpContext.Current.Response.Redirect("Default.aspx")
End If
cn = New Oracle.DataAccess.Client.OracleConnection("Data Source=" & sIntDB & "; User Id=" & UserId & "; Password=" & Password & "; Pooling=False;")
End Sub
Public Function AddressLookup(ByVal sStreetNum As String) As DataSet
da = New OracleDataAdapter("Select Distinct SERVICE_ADDRESS From APP_CMDS.SERVICE_ADDRESS_VIEW Where SERVICE_ADDRESS Like '" & UCase(sStreetNum) & "%' And RowNum <= 10", cn)
Dim ds As New DataSet
Dim ocb As New OracleCommandBuilder(da)
da.Fill(ds)
Return ds
End Function
Public Sub Dispose() Implements IDisposable.Dispose
If IsDisposed = False Then
cn.Close()
GC.SuppressFinalize(Me)
IsDisposed = True
End If
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
Dispose()
End Sub
End Class
### Web.config ####
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
<assemblies>
<add assembly="Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Generic"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Linq"/>
<add namespace="System.Xml.Linq"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
</pages>
<authentication mode="Windows"/>
</system.web>
</configuration>
Running localhost I get this error:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30560: 'OracleConnection' is ambiguous in the namespace 'Oracle.DataAccess.Client'.
Source Error:
Line 6: Implements IDisposable Line 7: Public IsDisposed As Boolean = False Line 8: Dim cn As Oracle.DataAccess.Client.OracleConnection Line 9: Dim da As OracleDataAdapter Line 10:Source File: C:\Inetpub\wwwroot\LaserTest\LaserTest\App_Code\OracleDataAccess.vb Line: 8
When I publish I get this error:
Server Error in '/applications/_laser' Application.
Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error:
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Oracle.DataAccess' could not be loaded.
Stack Trace:
kraznodar
Contributor
3332 Points
881 Posts
Re: Compiler Error Message: BC30560: 'OracleConnection' is ambiguous in the namespace 'Oracle.Dat...
Jun 11, 2012 04:03 PM|LINK
Apparently it is something with the web.config file. I deleted the web.config that didn't work and copied over the one that did and now the "broken" project works fine. Unfortunately when I create a new project the web.config is bad so I have to copy in an old one.
One thing I noticed is the utf-16 encoding in the web.config that works. I also notice that even though I'm setting my Oracle reference to C:\app\oracle\product\11.2.0.2\odac32\odp.net\bin\2.x\Oracle.DataAccess.dll, the assemblies section has this; <add assembly="Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
I'm not marking this answered until I figure out why things are this way.