dimanche 1 mars 2015

Assembly Load Failure in Unit Test

I am writing a Visual Studio 2013 unit test which requires the loading of a DLL but it is failing. The fully qualified dll is specified in the unit test's app.config.


It seems the unit test engine is not looking for the DLL in the bin/debug folder as I expect. The DLL is in the bin/debug folder.


This is the code I am using to load the dll but fails when calling Type.GetType(typeName).


app.config:



<add key="RepositoryType" value="RepositoryDB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>


Code to load assembly:



String typeName = ConfigurationManager.AppSettings["RepositoryType"];
Type repoType = Type.GetType(typeName);
object repoInstance = Activator.CreateInstance(repoType);
IRepository repo = repoInstance as IRepository;


This is the exception:



System.IO.FileLoadException was unhandled
HResult=-2146234297
Message=The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName)
InnerException:





Aucun commentaire:

Enregistrer un commentaire