Difficulty in Loading the type from the referenced assembly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madankarmukta
    Contributor
    • Apr 2008
    • 308

    Difficulty in Loading the type from the referenced assembly

    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>
    Code:
     
    
        interface ITest<T> 
        {        
            //CRUD
            void Create();
            void Insert(T t);
            void Update(T t);
            void Delete(T t);
            void Save();
        }
    2) A Container to create the ITest reference. The container holds a static method that returns ITest<T>

    Code:
     
    
     public class Repository
        {
            public static ITest<T> GetInterfaceRepository<T>(string dll,string type)
            {
                try 
                {
                    var i = Activator.CreateInstance(dll, type) as ObjectHandle; 
    
    //Here it is Giving an error as 
    //Could not load type 'ClassTest' from assembly 'Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    
                    var retval = i.Unwrap() as ITest<T>; return retval; 
                }
                catch (Exception E) 
                { 
                   throw E;
                }
            }
        }
    3) The consumer is as -

    Code:
     
    ITest<ClassTest> iRepos = Repository.GetInterfaceRepository<ClassTest>("dllPathFor_ClassTest", "ClassTest");
    
    iRepos.Create();
    Test.dll is the assembly getting referenced and pertains the type ClassTest.

    Please guide if anybody have suggestion on.
Working...