Activator.CreateInstance(typeof(void)) [.NET 2.0]

  • Thread starter Thread starter sorin.ionescu
  • Start date Start date
S

sorin.ionescu

In .NET 2.0, Activator.CreateInstance(typeof(void)) does not work
anymore.

System.NotSupportedException : Cannot dynamically create an instance of
System.Void.

In the documentation, only TypeBuilder, TypedReference, ArgIterator,
and RuntimeArgumentHandle types are listed as not supported.
 
ahum.. I just didn't understand your post.
Now, after some further reading, I don't quite understand it either except
the 1st line which is almost clear.

So, based on the content of the 1st line I would say, maybe it's a typo?

Try
Activator.CreateInstance<Void>()
instead of
Activator.CreateInstance<void>()

(V != v)
because there is a (System.)Void structure, but there is no such thing as a
void instance.
 
In .NET 2.0, Activator.CreateInstance(typeof(void)) does not work
anymore.

System.NotSupportedException : Cannot dynamically create an instance of
System.Void.

In the documentation, only TypeBuilder, TypedReference, ArgIterator,
and RuntimeArgumentHandle types are listed as not supported.

This is by design and documented, from the Void structure documentation

Remarks
This structure is used in the System.Reflection namespace. This structure
has no members, and you cannot create an instance of this structure.

Willy.
 
Back
Top