In this last week I've been working on the VS 2005 integration for our ADO Provider. Everything was going smooth. First ... then came testing on different real world machines and VM's. And suddenly there was nothing but trouble. After some busy hours bug fixing and retesting I was down to one obvious problem. One some machines it would happen that at the end of the "New Datasource Wizard" an error "Failed to find or load the registered .NET framework data provider." appeared deep in VS code territory. The same error popped up on few other places, mostly when pressing Preview in the "Preview Data" dialog. Now there's quite a few references to this error when googling, but none of the suggested resolutions (including copying dlls, reinstalling VS, cleaning old beta entries [if there], ...) was successful. After hours and hours of debugging I finally found the culprit. A badly coded DbProviderFactory.GetFactoryFromType in Microsoft.VSDesigner.dll.
EnsureFactoryTable(); foreach (DataRow row in factoryTable.Rows) { DbProviderFactory factory = DbProviderFactories.GetFactory(row); string providerName = (string) row[PROVIDER_NAME]; object obj2 = CreateObject(factory, kindOfObject, providerName); if (type.Equals(obj2.GetType())) { providerData.Initialize(factory, (string)row[PROVIDER_INVARIANT_NAME], (string) row[PROVIDER_NAME], type); return factory; } } throw new InvalidAdoNetProviderException(string.Format("Unable to find DbProviderFactory for type {0}", type.ToString()));
As you can see it's iterating through the list of registered providers which it apparently gets from the machine.config file, creates a connection and match the types. The problem though is if ANY of the providers that is registered before the one you're just working with is not registered correctly or there's a problem loading it the DbProviderFactories.GetFactory(row) or CreateObject(factory, kindOfObject, providerName) will fail and trigger an exception.
Solution: Make sure that all registered providers are actually working correctly. Make sure that for every registered provider in the IDE (registry: hklm\Software\Microsoft\VisualStudio\8.0\DataProviders) you have a matching entry in machine.config. Also make sure that the providers actually are still installed and are actually working in VS design mode. For example on my machine for whatever reason I had a SQLServerCe provider registered in machine.config, which existed and worked fine at runtime, but which was not designed to work with VS in design mode. To keep it working I simply moved it to the last entry in the machine.config's data providers section. If nothing else helps clear out all providers and put one after the back until you find the culprit.