By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

Difficulty in Loading the type from the referenced assembly

100+
P: 293
Hi All,

I am facing a problem while loading the type from the referenced assembly.

I am implementing the Dependency Injection Design Pattern in the application. Here is the code
1) I have the ITest.cs - ITest<T>
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.     interface ITest<T> 
  4.     {        
  5.         //CRUD
  6.         void Create();
  7.         void Insert(T t);
  8.         void Update(T t);
  9.         void Delete(T t);
  10.         void Save();
  11.     }
  12.  
2) A Container to create the ITest reference. The container holds a static method that returns ITest<T>

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  public class Repository
  4.     {
  5.         public static ITest<T> GetInterfaceRepository<T>(string dll,string type)
  6.         {
  7.             try 
  8.             {
  9.                 var i = Activator.CreateInstance(dll, type) as ObjectHandle; 
  10.  
  11. //Here it is Giving an error as 
  12. //Could not load type 'ClassTest' from assembly 'Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
  13.  
  14.                 var retval = i.Unwrap() as ITest<T>; return retval; 
  15.             }
  16.             catch (Exception E) 
  17.             { 
  18.                throw E;
  19.             }
  20.         }
  21.     }
  22.  
3) The consumer is as -

Expand|Select|Wrap|Line Numbers
  1.  
  2. ITest<ClassTest> iRepos = Repository.GetInterfaceRepository<ClassTest>("dllPathFor_ClassTest", "ClassTest");
  3.  
  4. iRepos.Create();
  5.  
Test.dll is the assembly getting referenced and pertains the type ClassTest.

Please guide if anybody have suggestion on.
May 28 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.

Browse more .NET Framework Questions on Bytes