martinjw / dbschemareader

Read database metadata (from SqlServer/Oracle/MySql/SQLite/PostgreSql/DB2 etc) into one simple model
Microsoft Public License
293 stars 128 forks source link

Load DbProviderFactory from external assembly with AssemblyLoader #46

Closed thomasjoscht closed 7 years ago

thomasjoscht commented 7 years ago

Currently loading external DbProviderFactory in GetFactory() implementation is based on Type.GetType(...). this will fail (in my case) everytime returning null. This can also be reproduced trying Type.GetType() directly after AppDomain.CurrentDomain.Load(...) which will return everytime null.

My implementation uses a simple AssemblyLoader as static helper class. It uses Type.GetType overloading with AssemblyResolver function. NOTE: This is only possible in .NET 4+. Therefore a new build constant was necessary.

EDIT: I see test case TestRepository has failed because of FileNotFoundException of direct referenced System.Data.SQlite. In my case the assemblies aren't referenced directly. Perhaps turning throwOnError to false of GetType could solve this.

EDIT2: I've tested locally with a direct referenced db provider which works in my case without throwing a FileNotFoundException or so on.

thomasjoscht commented 7 years ago

I've adjusted the AssemblyHelper a little bit. Now the old mechanismn with Type.GetType(assemblyQualifiedName) will be used first. In case it doesn't work the .NET 4+ specific method with custom assembly resolver will be used. Also throwOnError is set to false. This should work in all old environments. This works now also in my environment f.e. for Npgsql without any configuration in app.config, without direct dependency to lib and without assembly must be lied in same directory as application. Can you confirm this?

martinjw commented 7 years ago

Thanks- will try in a day or 2...