How can I render an ASP .NET user control outside of the ASP .NET runtime?
<p>I am generating an HTML email using an ASP .NET user control, as follows</p>

<pre><code>private string GetHtml(object myData)
{
    var page = new Page();
    var control = page.LoadControl("~/path/to/myEmailControl.ascx");
    page.Controls.Add(control);
    control.DataBind(myData);
    return RenderControlToHtml(control);
}

private string RenderControlToHtml(Control control)
{
    var builder = new StringBuilder();
    control.RenderControl(new HtmlTextWriter(new StringWriter(builder)));
    return builder.ToString();
}
</code></pre>

<p>This works fine when I use it from a web project, but recently we've added a Windows app to the solution which also needs to use this code.</p>

<p>Does anyone have any suggestions as to how I could get the code to work outside of the ASP .NET runtime? Once I've got an instance of a control I should be able to render it, but it's the loading of the control from the ascx file that is the problem.</p>
