LUKIYA'S NEVERLAND

春去秋来,花谢花开。


Original Url: http://forums.l-space-design.com/blogs/day_of_the_developer/archive/2006/08/12/223.aspx

I thought the "Web Deployment" addin for VS 2005 was great.  Until I used it on a site using profiles.

Now I get (in production only) the following exception:

System.ArgumentNullException

Message: Value cannot be null.
Parameter name: type
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Web.Profile.ProfileBase.CreateMyInstance(String username, Boolean isAuthenticated)
   at System.Web.Profile.ProfileBase.Create(String username, Boolean isAuthenticated)
   at System.Web.HttpContext.get_Profile()

Here is the code for CreateMyInstance

private static ProfileBase CreateMyInstance(string username, bool isAuthenticated)
{
      Type type1;
      if (HostingEnvironment.IsHosted)
      {
            type1 = BuildManager.GetProfileType();
      }
      else
      {
            type1 = ProfileBase.InheritsFromType;
      }
      ProfileBase base1 = (ProfileBase) Activator.CreateInstance(type1);
      base1.Initialize(username, isAuthenticated);
      return base1;
}

The bold line is where the exception must be thrown.

Much hunting and searching through "InheritsFromType" makes me think that it's got confused because of the new assemly name.  Nothing is fixing it though.

Guess what.  HostingEnvironment.IsHosted returns TRUE

public static bool IsHosted
{
      get
      {
            return (HostingEnvironment._theHostingEnvironment != null);
      }
}

So BuildManager.GetProfileType is at fault, or IsHosted should be returning false.

It returns true in my testing under IIS, so it must be GetProfileType that is at fault.

That's confirmed.  BuildManager.GetProfileType() is returning null. 

Now to find out why.

BuildManager.CodeAssemblies also returns null.

That gets assigned any time that CompileCodeDirectory successfully builds an assembly based on a directory.

That is called (indirectly) multiple times from EnsureTopLevelFilesCompiled() unless an exception occurs (which is not reported to me, and should be). EnsureTopLevelFilesCompiled() is called when GetProfileType() is called.

All of which implies that CompileCodeDirectory fails in some way.


Ahah!

 

If the bin directory contains this file:

App_Code.compiled

Then it works.  That means in the "Web Deployment" properties, uncheck "Treat as library component"

But that's not going to help if I need to merge this set of code with another set on the same website unless you can merge multiple versions of that file into a single file.

Still, it will do for now.