- Home /
Activator can't create array and string?
Hey!
I know this is probably not an issue with unity, but I can't see what's been updated or changed recently. Problem is I used the System.Activator.CreateInstance method to dynamically create classes and it worked fine until yesterday. Now suddenly it can't create instances of arrays and strings. Do you guys have this issue? Please test this: System.Activator.CreateInstance(typeof(string));
. I understand why it would make no sense to have a default string constructor but it used to work.
Thanks!
Answer by HarshadK · Aug 30, 2017 at 09:03 AM
If you take a look at implementation of static public T CreateInstance<T>()
method inside Activator class source you can check out the comment for throwing MissingMethodException there which states that:
Array, Ref, and Pointer types don't have default constructors.
And since you are trying to create an object with default constructor here, it is throwing the error.
Thanks that will work. Do you happen to know when this was changed?
Can not say with authority when the change took place but the comment above the line of comment from my answer states that: "This is a hack to maintain compatibility with V2." So it is sure the change came after V2. ;-)
Your answer

Follow this Question
Related Questions
Object Instance Data Declaration without Constructors 1 Answer
Apply changes on asset to instance 1 Answer
Player not moving due to static instance : is dynamic instancing a thing ? 1 Answer
Constructor Problem in Unityscript 1 Answer
Why are all forms of the Material constructor hidden in the documentation? 0 Answers