Reassembling your website with Resharper 6

I recently found myself in the position where I needed to reassemble an ASP.Net site from its deployed files.

The first part was easy, create a website project and pull in the front-end files, then it was on to the harder parts, recreating the backing code and making sense of the minified files.

The first part was easy, create a website project and pull in the front-end files, then it was on to the harder parts, recreating the backing code and making sense of the minified files.

For minified js files try jsbeautifier.

To recreate the code I used Resharper 6’s new code disassemble feature (F12 when in the object browser) and being a small project it was feasible to do this manually rather than via scripts or automation.

I wanted to write this post to highlight a couple of issues, gotcha’s that cost me some time.

Example

    protected void Page_Load(object sender, EventArgs e)
    {
      // ISSUE: unable to decompile the method.
    }

Solution

Make sure that all the dlls referenced by file you are disassembling are in the same directory.

Example compile error.

Could not load the assembly 'myAssembly'.
Make sure that it is compiled before accessing the page.
C:\Code\..\Control.ascx

Note, you will only get this if you delete the dll’s from the bin directory.

Solution

 
Pages and controls need to be re-pointed at the disassembled code e.g.

Change this…

<%@ control language="C#" autoeventwireup="true" 
inherits="MyControlName, MyWebsiteDLLName" %>

To this…

<%@ control language="C#" autoeventwireup="true" 
CodeFile="MyControlName.ascx.cs" inherits="MyControlName" %>

Example

A number of properties that I pasted in from the disassembled code had this compile error:

Solution

The disassembled code had generated a single file for the two partial classes of the webform.

Generated code:

// Type: MyNameSpace.MyPage
// Assembly: CardCustomisation, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Assembly location: C:\Code\MyWebSite.dll

using System;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;

namespace MyCode
{
  public class MyPage : Page, IRequiresSessionState
  {
    protected TextField txtName;

    protected DefaultProfile Profile
    {
      get
      {
        return (DefaultProfile) this.Context.Profile;
      }
    }

    protected HttpApplication ApplicationInstance
    {
      get
      {
        return this.Context.ApplicationInstance;
      }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        DoSomeWork();
    }
  }
}

To fix it, I removed the properties that existed in the aspx file from the disassembled code and made it a partial class.

// Type: MyNameSpace.MyPage
// Assembly: CardCustomisation, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Assembly location: C:\Code\MyWebSite.dll

using System;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;

namespace MyCode
{
  public partial class MyPage : Page, IRequiresSessionState
  {
    protected void Page_Load(object sender, EventArgs e)
    {
        DoSomeWork();
    }
  }
}