c# - System.InvalidCastException in Unit Test with Oracle objects using DbProviderFactory -
when using system.data.common.dbproviderfactory error when run our code in nunit test not when run regular web application.
error
system.invalidcastexception : [a]oracle.dataaccess.client.oracleparameter cannot cast [b]oracle.dataaccess.client.oracleparameter. type originates 'oracle.dataaccess, version=2.112.1.2, culture=neutral, publickeytoken=89b483f429c47342' in context 'default' @ location 'c:\windows\assembly\gac_32\oracle.dataaccess\2.112.1.2__89b483f429c47342\oracle.dataaccess.dll'. type b originates 'oracle.dataaccess, version=4.112.1.2, culture=neutral, publickeytoken=89b483f429c47342' in context 'default' @ location 'c:\windows\microsoft.net\assembly\gac_32\oracle.dataaccess\v4.0_4.112.1.2__89b483f429c47342\oracle.dataaccess.dll'.
we have 2.112.1.2 assembly referenced unit test project , tried 'use specific version' , 'copy local' doesn't see dll continues load newer version in gac.
turns out dll not copied on executing folder of test runner. luckily can specify specific dll load out of gac.
we added app.config in unit test project. note specific assembly version in type attribute of <add />
element
<system.data> <dbproviderfactories> <clear /> <add name="oracle data provider" invariant="oracle.dataaccess.client" description=".net framework data provider oracle" type="oracle.dataaccess.client.oracleclientfactory, oracle.dataaccess, version=2.112.1.2, culture=neutral, publickeytoken=89b483f429c47342" /> </dbproviderfactories> </system.data>
Comments
Post a Comment