- Home /
Question by
KaiserJohan · Mar 28, 2012 at 08:22 AM ·
c#pc
C# - Reflection to invoke static method freezes unity
Hello,
I have a class like this:
namespace MyTest
{
public interface TestI
{
//....
}
public class Test : TestI
{
public static Test GetInstance()
{
if (instance == null)
{
instance = new Test();
}
return instance;
}
// ....
}
}
I have built it into a dll called "Test.dll". Now I want to invoke this static method with reflection.
private void Start()
{
Assembly assembly = Assembly.LoadFrom("Test.dll");
Type type = assembly.GetType("MyTest.Test");
MethodInfo mi = type.GetMethod("GetInstance");
MyTest.TestI test= (MyTest.TestI)mi.Invoke(null, null);
}
None of calls in Start() return null, it appears to go through, but whenever I try to call a method Unity just freezes. What am I doing wrong?
EDIT: running on PC, but will eventually run on android/ios too. I get no exceptions.
Comment
Same thing here with both $$anonymous$$ethod and Properties. Unity doesn't appear to like reflected static members.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065626im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
C# Reflection and Android/IOS 1 Answer
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer