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();
}

3 comments:

Anonymous said...

when creating a guid if you pass in a null or empty string you can get the above error. i.e.

Guid g = new Guid("");
or
Guid g = new Guid(null);

Marquito said...

Thanks man. The Guid(null) was the key to it.

Anonymous said...

Muchas gracias por su ayuda, El Guid(null) Era la causa del error en mi aplicaciĆ³n.

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