سؤال

I am getting the InvalidCastException from DB while trying to call a method. Can someone help me fixing this. Thank you.

Exception:

Execute
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: [A]Oracle.DataAccess.Client.OracleCommand cannot be cast to [B]Oracle.DataAccess.Client.OracleCommand. Type A originates from 'Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_64\Oracle.DataAccess\v4.0_4.112.3.0__89b483f429c47342\Oracle.DataAccess.dll'. Type B originates from 'Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' in the context 'Default' at location 'C:\Windows\assembly\GAC_64\Oracle.DataAccess\2.112.3.0__89b483f429c47342\Oracle.DataAccess.dll'.
   at .DAO.ApplicationDetailsBODataAccess.GetApplicationXmlDataSelectionFactory.ConstructSelectCommand(Database db, ApplicationDetailsBO applicationData) in C:\Projects\Source\\Development\Release19.0\Source\SharedSource\.DAO\ApplicationRepositoryArtifacts\GetApplicationXmlData\GetApplicationXmlDataSelectionFactory.cs:line 37
   at Microsoft.Practices.Repository.Repository`1.Find[TIdentity](ISelectionFactory`1 selectionFactory, IDomainObjectsFactory`1 domainObjectFactory, TIdentity identity) in C:\Projects\Source\iCIS\Common\Source\RepositoryFactory\DataAccess Guidance Package\Microsoft.Practices.Repository\Repository.cs:line 97
   at .DAO.ApplicationDetailsBODataAccess.ApplicationDetailsRepository.GetApplicationXmlData(ApplicationDetailsBO applicationData) in C:\Projects\Source\\Development\Release19.0\Source\SharedSource\.DAO\ApplicationRepositoryArtifacts\ApplicationDetailsRepositoryImplementation.cs:line 103
   at .BWC.ApplicationBWC.GetApplication(ApplicationDetailsBO applicationData) in C:\Projects\Source\\Development\Release19.0\Source\SharedSource\.BWC\ApplicationBWC.vb:line 411
   at .BWC.GatepostBWC.VerifyDemographicInfo(ApplicationDetailsBO applicationDetails) in C:\Projects\Source\\Development\Release19.0\Source\SharedSource\.BWC\GatepostBWC.vb:line 599
   --- End of inner exception stack trace ---
   at MbUnit.Framework.Reflection.Reflector.InvokeMethod(AccessModifier access, Object obj, String methodName, Boolean lookInBase, Object[] methodParams) in c:\RelEng\Projects\MbUnit v3.1\Work\src\MbUnit\MbUnit\Framework\Reflection\Reflector.cs:line 460
   at MbUnit.Framework.Reflection.Reflector.InvokeMethod(AccessModifier access, Object obj, String methodName, Object[] methodParams) in c:\RelEng\Projects\MbUnit v3.1\Work\src\MbUnit\MbUnit\Framework\Reflection\Reflector.cs:line 443
   at MbUnit.Framework.Reflection.Reflector.InvokeMethod(AccessModifier access, String methodName, Object[] methodParams) in c:\RelEng\Projects\MbUnit v3.1\Work\src\MbUnit\MbUnit\Framework\Reflection\Reflector.cs:line 197
   at .BWC.Tests.GatepostBWCTest.verifyDemographicInfoTest() in C:\Projects\Source\\Development\Release19.0\Source\SharedSource\.BWC.Tests\GatepostBWCTest.vb:line 373

لا يوجد حل صحيح

نصائح أخرى

By viewing the top of the exception details only, you can notice that you have a version mismatch. The code is trying to cast the same type (OracleCommand) from different versions of the DataAccess.dll: 2.112.3.0 vs 4.112.3.0:

[A]Oracle.DataAccess.Client.OracleCommand cannot be cast to [B]Oracle.DataAccess.Client.OracleCommand. Type A originates from 'Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_64\Oracle.DataAccess\v4.0_4.112.3.0__89b483f429c47342\Oracle.DataAccess.dll'. Type B originates from 'Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' in the context 'Default' at location 'C:\Windows\assembly\GAC_64\Oracle.DataAccess\2.112.3.0__89b483f429c47342\Oracle.DataAccess.dll'. at

Both of the DataAccess.dll seems to come from the Global Assembly Cache, so now the question is why your code references two different versions. I assume that posting the code that performs the actual invocation (GetApplicationXmlDataSelectionFactory.cs at line 37) might provide more information.

Edit: By viewing the rest of the exception, it seems that the error originates in the IoC framework you are using (MbUnit) - it loads the wrong version of the DataAccess DLL in reflection.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top