Activator.CreateInstance can't find the constructor (MissingMethodException)

后端 未结 9 2267
一个人的身影
一个人的身影 2021-02-18 15:55

I have a class which has the following constructor

public DelayCompositeDesigner(DelayComposite CompositeObject)
{
    InitializeComponent();

    compositeObjec         


        
9条回答
  •  一生所求
    2021-02-18 16:25

    I discovered another way of creating an instance of an object without calling the constructor at all while answering another question on SF.

    In the System.Runtime.Serialization namespace there is a function FormatterServices.GetUninitializedObject(type) that will create an object without calling constructor.

    If you look at that function in Reflector you will see it is making an external call. I don't know how black magic is actually happening under the hood. But I did prove to myself that the constructor was never called but the object was instantiated.

提交回复
热议问题