Understanding When Type.FullName Returns Null in .NET

 
 
  • Gérald Barré

A colleague recently asked me: "Why does Type.FullName return null in certain situations?" The method signature makes this possibility explicit:

C#
public abstract string? FullName { get; }

While this behavior may seem unexpected, the .NET runtime cannot generate a valid full name in some scenarios. The two main cases where Type.FullName returns null are:

#Generic Types with Open Type Parameters

When a generic type contains unbound (open) type parameters:

C#
var list = typeof(IList<>);
var dict = typeof(IDictionary<,>);
var listOfDictionaries = list.MakeGenericType(dict); // IList<IDictionary<,>>
Assert.Null(listOfDictionaries.FullName);

#Function Pointers

Function pointer types introduced in C# 9 also have null as their FullName:

C#
var functionPointerType = typeof(delegate*<int, void>);
Assert.Null(functionPointerType.FullName);

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?