Thursday, December 11, 2008

ArgumentNullException raised by Profile when deploying a web project

Your ASP.NET web site works perfectly in your development environment and you build a Visual Studio Web Deployment Project to deploy it in a production environment. You launch the default page and you get:

Value cannot be null.
Parameter name: type

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: type

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentNullException: Value cannot be null. Parameter name: type]
System.Activator.CreateInstance(Type type, Boolean nonPublic) +2843963
System.Web.Profile.ProfileBase.CreateMyInstance(String username, Boolean isAuthenticated) +76
System.Web.Profile.ProfileBase.Create(String username, Boolean isAuthenticated) +312
System.Web.HttpContext.get_Profile() +108
Global.Application_AcquireRequestState(Object sender, EventArgs e) +72
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

The solution to this problem is hidden in the Web Deployment Project property pages. Select the "Output Assemblies" node under "Configuration Properties" and below the "Merge all outputs to a single assembly" option, uncheck "Treat as library component (remove App_code.compiled file)".