문제

When using System.Data.Common.DbProviderFactory with we get this error when we run our code in an NUnit test but not when we run the regular web application.

Error

System.InvalidCastException : [A]Oracle.DataAccess.Client.OracleParameter cannot be cast to [B]Oracle.DataAccess.Client.OracleParameter. Type A originates from 'Oracle.DataAccess, Version=2.112.1.2, Culture=neutral, PublicKeyToken=89b483f429c47342' in the context 'Default' at location 'C:\Windows\assembly\GAC_32\Oracle.DataAccess\2.112.1.2__89b483f429c47342\Oracle.DataAccess.dll'. Type B originates from 'Oracle.DataAccess, Version=4.112.1.2, Culture=neutral, PublicKeyToken=89b483f429c47342' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_32\Oracle.DataAccess\v4.0_4.112.1.2__89b483f429c47342\Oracle.DataAccess.dll'.

We have the 2.112.1.2 assembly referenced by the unit test project and we even tried 'use specific version' and 'copy local' but it just doesn't see that DLL it continues to load from a newer version in the GAC.

도움이 되었습니까?

해결책

Turns out the dll is not copied over to the executing folder of the test runner. Luckily you can specify the specific dll to load out of the GAC.

We added this to the app.config in the unit test project. Note the specific assembly version in the type attribute of the <add /> element

<system.data>
    <DbProviderFactories>
      <clear />
      <add name="Oracle Data Provider" invariant="Oracle.DataAccess.Client" 
           description=".Net Framework Data Provider for Oracle" 
           type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=2.112.1.2, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
</system.data>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top