views:

14

answers:

1

I'm having a really strange issue with MSTest. I have a test that is more of an integration test, and needs to connect to the database. It does this by getting the ADO.NET data provider factory through a call to:

var factory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");

In my app.config file, I have:

<system.data>
  <DbProviderFactories>
    <add name="Oracle Data Provider" invariant="Oracle.DataAccess.Client" description=".Net Framework Data Provider for Oracle" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess" />

This works perfectly fine and the test passes if I run it in Visual Studio. However, if I open a command prompt, and run it using MSTest.exe /testcontainer:... Then my test fails, with the exception:

System.Configuration.ConfigurationErrorsException
Message:  Failed to find or load the registered .Net Framework Data Provider.

The odd thing is that if I query the DBProviderFacotry classes, I do see my "Oracle.DataAccess.Client" provider, but trying to actually get an instance of it throws an exception:

var name = DbProviderFactories.GetFactoryClasses().Rows[1]["InvariantName"]; // returns "Oracle.DataAccess.Client"
var fact = DbProviderFactories.GetFactory("Oracle.DataAccess.Client"); // throws exception

Again, this only fails when run from the MSTest.exe command line, and works fine in VisualStudio 2008. Anyone have any ideas?


Update:

I found out another interesting detail... In my app.config, I actually do a clear of the provider collection before adding my oracle entry, because if it already existed in machine.config, it would cause errors:

<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" />

Now, what I just found is that if I completely remove this from the app.config, and don't specify the DbProviderFactories at all, then it works fine!

Strange...


Update 2

OK, I guess I sort of figured this out. In my app.config, if I specify the full/strong name for the assembly, then it works, in both VisualStudio, and from the command line:

<add name="Oracle Data Provider"
  invariant="Oracle.DataAccess.Client"
  description="Oracle Data Provider for .NET" 
  type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=2.111.7.20, Culture=neutral, PublicKeyToken=89b483f429c47342" />

But the short name only works in VisualStudio, not on the command line:

<add name="Oracle Data Provider"
  invariant="Oracle.DataAccess.Client"
  description=".Net Framework Data Provider for Oracle"
  type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess" />

Now I just wish I understood why... :)

A: 

Answering my own question here, but I finally figured this out:

My Oracle.DataAccess.dll does end up in my \bin\Debug folder when VisualStudio builds it. However, when MSTest.exe runs, it does not copy that .dll to the new folder where the test is actually run. For some reason it copies the other 30-some files, but not that one?

Anyway, thats why adding the full assembly name worked; because then it could load it from the GAC instead of the local folder.

rally25rs