Unable to cast object of type 'EntLibContrib.Data.OdpNet.Configuration.OracleConnectionSettings' to type 'Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings'

Topics: Development Team Discussion, User Discussion
Feb 8, 2012 at 11:11 AM
Edited Feb 8, 2012 at 12:45 PM

Hi all,

I use ODP.NET and version 4.1 of the Enterprise Library, vs 2008. And all is OK.

Now, migrate using ODP.NET Oracle.DataAccess 4.112.2.0 and version 5.0.414.0 of the Enterprise Library, vs 2010, .net 4.0. Using Windows7 64 bits.

Now,  I have download source code of http://entlibcontrib.codeplex.com/

I open Data.OdpNet.QuickStarts.sln and change references to Enterprise Library 5.0.414.0. and change Target Framework to .NET 4.0. Now it works using right configuration.

Both 4.1 and 5.0 dlls are on GAC in Windows 7 64 bits. EntLibContrib.Data.OdpNet is in GAC too. All is OK.


I have now a machine with Windows Server 2008 64 bits, on which is installed Enterprise Library 5.0 and 4.1. Both 4.1 and 5.0 dlls are on GAC and must be. EntLibContrib.Data.OdpNet is in GAC too.

Application in Win7 64bits and W2008 64bits is Biztalk (Host) that use EntLib 5.0 Data + EntLib.Contrib + ODP.NET


I get this error:

   Unable to cast object of type 'EntLibContrib.Data.OdpNet.Configuration.OracleConnectionSettings' to type 'Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings'.

Any solution about it ?

Thanks in advanced.

References: http://entlib.codeplex.com/workitem/31936

 UPDATE: I dont know the reason, if comment there's no error in W2008 64 bits: <oracleConnectionSettings>  and

 

<section name="oracleConnectionSettings" type="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=709072f976b4c05b" requirePermission="true" />

 

My config is:

<section name="oracleConnectionSettings" type="EntLibContrib.Data.OdpNet.Configuration.OracleConnectionSettings, EntLibContrib.Data.OdpNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=709072f976b4c05b" requirePermission="true"/>


<system.data>
  <DbProviderFactories>
    <add name="EntLibContrib.Data.OdpNet"
      invariant="EntLibContrib.Data.OdpNet"
      description="EntLibContrib Data OdpNet Provider"
      type="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=709072f976b4c05b" />
  </DbProviderFactories>
</system.data>

<dataConfiguration defaultDatabase="DAL.Properties.Settings.ConnectionString">
  <providerMappings>
    <add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=709072f976b4c05b"
      name="System.Data.OracleClient" />

    <add databaseType="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=709072f976b4c05b"
         name="EntLibContrib.Data.OdpNet"/>

  </providerMappings>
</dataConfiguration>

<oracleConnectionSettings>
  <add name="DAL.Properties.Settings.ConnectionString"></add>
</oracleConnectionSettings>

<oracle.dataaccess.client configSource="Config\oracle.dataaccess.client.config"/>

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

    <qualifyAssembly partialName="Oracle.DataAccess" fullName="Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />

    <qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Data" fullName="Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=709072f976b4c05b"/>

  </assemblyBinding>

  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="709072f976b4c05b" culture="neutral" />
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.1.505.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.Unity.Configuration" publicKeyToken="709072f976b4c05b" culture="neutral" />
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.1.505.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Common" publicKeyToken="709072f976b4c05b" culture="neutral" />
      <bindingRedirect oldVersion="1.0.0.0-4.2.0.0" newVersion="5.0.414.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Data" publicKeyToken="709072f976b4c05b" culture="neutral" />
      <bindingRedirect oldVersion="1.0.0.0-4.2.0.0" newVersion="5.0.414.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Logging" publicKeyToken="709072f976b4c05b" culture="neutral" />
      <bindingRedirect oldVersion="1.0.0.0-4.2.0.0" newVersion="5.0.414.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" publicKeyToken="709072f976b4c05b" culture="neutral" />
      <bindingRedirect oldVersion="1.0.0.0-4.2.0.0" newVersion="5.0.414.0" />
    </dependentAssembly>
    
  </assemblyBinding>


</runtime>


Error details

 

Inner exception: Exception has been thrown by the target of an invocation.

 

Exception type: TargetInvocationException

Source: mscorlib

Target Site: System.Object _InvokeConstructor(System.IRuntimeMethodInfo, System.Object[], System.SignatureStruct ByRef, System.RuntimeType)

The following is a stack trace that identifies the location where the exception occured

 

   at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct& signature, RuntimeType declaringType)

   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)

   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.CreateDatabaseData(Type configurationElementType, ConnectionStringSettings settings, IConfigurationSource source)

   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.GetDatabaseData(ConnectionStringSettings connectionString, DatabaseSettings databaseSettings)

   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.<get_Databases>d__0.MoveNext()

   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)

   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.<DoGetRegistrations>d__10.MoveNext()

   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()

   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)

   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.GetRegistrations(IConfigurationSource configurationSource)

   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.TypeLoadingLocator.GetRegistrationsInternal(IConfigurationSource configurationSource, Func`3 registrationAccessor)

   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<>c__DisplayClass5.<GetRegistrationsInternal>b__4(ITypeRegistrationsProvider l)

   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()

   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider)

   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ChangeTrackingContainerConfigurator.RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider)

   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet()

   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()

   at ...   at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)

Additional error information:

         Unable to cast object of type 'EntLibContrib.Data.OdpNet.Configuration.OracleConnectionSettings' to type 'Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings'.

Exception type: InvalidCastException

Source: Microsoft.Practices.EnterpriseLibrary.Data

Target Site: Void .ctor(System.Configuration.ConnectionStringSettings, Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource)

The following is a stack trace that identifies the location where the exception occured

   at Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleDatabaseData..ctor(ConnectionStringSettings connectionStringSettings, IConfigurationSource configurationSource)

 

 

  < section name="oracleConnectionSettings" type="EntLibContrib.Data.OdpNet.Configuration.OracleConnectionSettings, EntLibContrib.Data.OdpNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=709072f976b4c05b" requirePermission="true" /> 

 

-->

<!--

Apr 8, 2013 at 5:04 PM
Team i have the exact Same issue. can we please get some help on this i am getting it on 505 version instead of 414