Monday, April 27, 2009

Value cannot be null. Parameter name: g

When programming in Sharepoint, if this error occurs check that there
is no Web.Config variable retrieval occuring at the private variable
declaration stage, e.g.

private string myString =
System.Configuration.ConfigurationManager.AppSettings["myString"].ToString();

where a Web.Config value that matches has not been declared in the
Web.Config file itself.

A far better practise is to retrieve such variables at the page load
stage, or in the constructor of your class, i.e.

private string myString = "";
public MyClass()
{
myString = System.Configuration.ConfigurationManager.AppSettings["myString"].ToString();
}

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Z