Click here to Skip to main content
15,943,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am loading one projects assembly in another project and there i am creating object of the classes. But those class's constructors calls one static method which causes exception as "Exception has been thrwon by target of an invocation"

Please sugest.........
Posted
Comments
Lakamraju Raghuram 8-Feb-12 1:49am    
I do not see any trouble in calling like this. I shouldn't be a problem if a constructor calls a static function.
May be some thing wrong with your arguments or in that static function
Sergey Alexandrovich Kryukov 8-Feb-12 4:42am    
Agree. Could be some different other reasons. Let's wait for some code sample from OP; there is no other way.
--SA
Sergey Alexandrovich Kryukov 8-Feb-12 2:10am    
There is more than one way to screw up things. Could you create a (short!) code sample? Use "Improve question" then.
--SA
ZurdoDev 8-Feb-12 8:39am    
It sounds like you are saying that the other dll is throwing an exception. So, why is it? Fix that issue.
BillWoodruff 8-Feb-12 10:30am    
Agree with all the other comments: show us some code, particularly the code where you "load one projects assembly in another project," and the code where you then create objects in that loaded assembly. And include the code for the static method in the imported assembly.

1 solution

i create the test code
C#
var type = typeof(TestClass);
var instance = Activator.CreateInstance(type);
((TestClass)instance).Print();


C#
public class TestClass
{
    public TestClass()
    {
        AnotherTestClass.Print();
    }
    public void Print()
    {
        Debug.WriteLine("### TestClass.Print Method Invoked");
    }
}
public class AnotherTestClass
{
    public static void Print()
    {
        Debug.WriteLine("### AnotherTestClass.Print Method Invoked");
    }
}


and it worked fine, i think the problem is in that static method that you call.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900