Error: "Value cannot be null. Parameter name: formType" retrieving default view page of document library

Few days ago I faced with the problem of linking to default view page of custom document library (for purposes of redirection with Source parameter after uploading new document and filling it’s meta data form).

At first I tried using SPList.Forms collection indexed with PAGETYPE enumeration as I found in article “How To Always Link to the Right Application Pages”. But every time I was trying to get the default view object this way:

var defaltViewUrl = documentLibrary.Forms[PAGETYPE.PAGE_DEFAULTVIEW].Url;

I was getting the following exception:

ArgumentNullException: "Value cannot be null. Parameter name: formType"

Fortunately this was working fine:

var defaultViewUrl = string.Format("{0}/{1}", documentLibrary.ParentWeb.Url, documentLibrary.DefaultView.Url);

I’ve checked that SPList.Forms collection returns valid forms/pages objects only for these three values:


For every other it throws arg null exception as described above. This looks definitely like a bad design in Sharepoint API (one of many…) - the collection should be indexed with other enum that contain valid set of values.

You can find some more detailed info about the reason of this strange behavior on the short StackOverflow thread started by my question. How Stefan figured out that error is caused by enum to string conversion? I guess this mystery was revealed with ILSpy or some similar tool ;-)


This post was originaly published on my previous blog and moved here. Some links and resources might not be up to date.

Marek Mierzwa

Marek Mierzwa
Husband, father, spiritual journeyman and in the meantime a software developer

Search as you type in Xamarin.Forms - the Reactive Extensions way

In [my previous post]({{ site.baseurl }}{% post_url 2018/2018-06-18-search-as-you-type-in-xamarin-forms %}) I showed how to introduce sea...… Continue reading