FormatterServices.GetUninitializedObject(Type) Method

Definition

Creates a new instance of the specified object type.

C#
public static object GetUninitializedObject(Type type);
C#
[System.Security.SecurityCritical]
public static object GetUninitializedObject(Type type);

Parameters

type
Type

The type of object to create.

Returns

A zeroed object of the specified type.

Attributes

Exceptions

The type parameter is null.

The caller does not have the required permission.

Remarks

Because the new instance of the object is initialized to zero and no constructors are run, the object might not represent a state that is regarded as valid by that object. The current method should only be used for deserialization when the user intends to immediately populate all fields. It does not create an uninitialized string, since creating an empty instance of an immutable type serves no purpose.

Note

You cannot use the GetUninitializedObject method to create instances of types that derive from the ContextBoundObject class.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1