<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Samurai Programmer.com - Premier Field Engineer (PFE)</title>
    <link>http://www.samuraiprogrammer.com/blog/</link>
    <description>I know kung fu</description>
    <language>en-us</language>
    <copyright>Greg Varveris</copyright>
    <lastBuildDate>Sat, 14 Aug 2010 17:45:39 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>greg@samuraiprogrammer.com</managingEditor>
    <webMaster>greg@samuraiprogrammer.com</webMaster>
    <item>
      <trackback:ping>http://www.samuraiprogrammer.com/blog/Trackback.aspx?guid=7e3dbca2-67a5-43c1-91d9-af075409b9c9</trackback:ping>
      <pingback:server>http://www.samuraiprogrammer.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.samuraiprogrammer.com/blog/PermaLink,guid,7e3dbca2-67a5-43c1-91d9-af075409b9c9.aspx</pingback:target>
      <dc:creator>Greg Varveris</dc:creator>
      <wfw:comment>http://www.samuraiprogrammer.com/blog/CommentView,guid,7e3dbca2-67a5-43c1-91d9-af075409b9c9.aspx</wfw:comment>
      <wfw:commentRss>http://www.samuraiprogrammer.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=7e3dbca2-67a5-43c1-91d9-af075409b9c9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/2010/07/29/AreYouReadyForYourNextChallengeWereHiring.aspx" target="_blank">
            <img style="border-right-width: 0px; margin: 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="11954221481914068549johnny_automatic_mister_fix_it_svg_hi" border="0" alt="11954221481914068549johnny_automatic_mister_fix_it_svg_hi" align="left" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/FixingtheDynamicControlsPlaceholdercontr_1B28/11954221481914068549johnny_automatic_mister_fix_it_svg_hi_8904f347-29ea-413f-bb83-420c018312a1.png" width="124" height="114" /> In
my job as a PFE</a> for <a href="http://www.microsoft.com">Microsoft</a>, I read,
review and fix a lot of code.  A lot of code.  It’s a large part of what
I love about my job.  The code is generally written by large corporations or <a href="http://www.codinghorror.com/blog/2008/12/the-problem-with-logging.html" target="_blank">for
public websites</a>.  Every now and again I’ll get pinged on an issue and after
troubleshooting the issue, it’s pretty clear that the core issue is with some community
code.  When I say community code, in this instance, I don’t mean a CodeProject
or CodePlex project.  In this case, I am referring to a control that <a href="http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx" target="_blank">Denis
Bauer created and then made available to the community on his website – the “DynamicControlsPlaceholder”
control</a>.  This is a great little control that inherits from a PlaceHolder
and allows you to  create dynamic controls on the fly and then it will persist
the controls you add on subsequent requests – like a postback.
</p>
        <h3>The Problem
</h3>
        <p>
The customer was experiencing a problem that could only be replicated in a web farm
when they don’t turn on <a href="http://stackoverflow.com/questions/1040025/difference-between-session-affinity-and-sticky-session" target="_blank">sticky
sessions</a>.  They found that when a request went from one server to another
server in their farm they would get a FileNotFoundException with the following details:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">Type Of Exception:FileNotFoundException<br />
Message:Error on page http://blahblahblah.aspx<br />
Exception Information:System.IO.FileNotFoundException: 
<br />
Could not load file or assembly 'App_Web_myusercontrol.ascx.cc671b29.ypmqvhaw, 
<br />
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. 
<br />
The system cannot find the file specified.<br />
File name: 'App_Web_myusercontrol.ascx.cc671b29.ypmqvhaw, 
<br />
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'<br />
at System.RuntimeTypeHandle.GetTypeByName(String name, 
<br />
Boolean throwOnError, 
<br />
Boolean ignoreCase, 
<br />
Boolean reflectionOnly, 
<br />
StackCrawlMark&amp; stackMark)<br />
...<br />
at DynamicControlsPlaceholder.RestoreChildStructure(Pair persistInfo, 
<br />
Control parent)<br />
at DynamicControlsPlaceholder.LoadViewState(Object savedState) 
<br />
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)<br />
...<br />
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)<br />
at System.Web.UI.Page.LoadAllState()<br />
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, 
<br />
Boolean includeStagesAfterAsyncPoint)</pre>
          <br />
        </div>
        <p>
So, we can gleam a few things from the error details:
</p>
        <ul>
          <li>
They are using the ASP.NET website model (the “app_web_….dll” assembly is the clue). 
</li>
          <li>
The error is occurring in the RestoreChildStructure method of the DynamicControlsPlaceholder
control. 
</li>
        </ul>
        <h3>The Research
</h3>
        <p>
The way that ASP.NET Websites work is that each component of your site can be compiled
into a separate assembly.  The assembly name is randomly generated.  This
also means that on two servers, the name of the assemblies can end up being different. 
So, an assumption to make is that something is trying to load an assembly by its name. 
If we look at the RestoreChildStructure method, we see the following:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <br />
Type ucType = Type.GetType(typeName[1], <span style="color: #0000ff">true</span>, <span style="color: #0000ff">true</span>);<br /><br /><span style="color: #0000ff">try</span><br />
{<br />
MethodInfo mi = <span style="color: #0000ff">typeof</span>(Page).GetMethod(<span style="color: #006080">"LoadControl"</span>, 
<br /><span style="color: #0000ff">new</span> Type[2] { <span style="color: #0000ff">typeof</span>(Type), <span style="color: #0000ff">typeof</span>(<span style="color: #0000ff">object</span>[])
});<br />
control = (Control) mi.Invoke(<span style="color: #0000ff">this</span>.Page, <span style="color: #0000ff">new</span><span style="color: #0000ff">object</span>[2]
{ ucType, <span style="color: #0000ff">null</span> });<br />
}<br /><span style="color: #0000ff">catch</span> (Exception e)<br />
{<br /><span style="color: #0000ff">throw</span><span style="color: #0000ff">new</span> ArgumentException(String.Format(<span style="color: #006080">"The
type '{0}' …"</span>, 
<br />
ucType.ToString()), e);<br />
}</pre>
          <br />
        </div>
        <p>
The important thing to look at here is the Type.GetType(…) call.  Since the code
for the control is in a separate assembly from everything else, the “typeName[1]”
value <strong>MUST BE A FULLY QUALIFIED ASSEMBLY NAME</strong>.  From the exception
details, we can see that it is attempting to load the type from the following string:
</p>
        <blockquote>
          <p>
            <strong>App_Web_myusercontrol.ascx.cc671b29.ypmqvhaw, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null</strong>
          </p>
        </blockquote>
        <p>
The “typeName[1]” variable is loaded from ViewState because that’s where the control
persists its child structure.  So, for some reason the fully qualified assembly
name is stored in ViewState.  If we look at the code that inserts the value into
ViewState (in the PersistChildStructure(…) method), we see:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <br />
typeName = <span style="color: #006080">"UC:"</span> + control.GetType().AssemblyQualifiedName; </pre>
          <br />
        </div>
        <p>
So, here we see the AssemblyQualifiedName is being stored into ViewState – which is
then used to persist the controls across postback using the above code.  As I
mentioned, this won’t work with an ASP.NET website hosted in a web farm because the
assembly qualified name will probably be different from server to server.  <a href="http://support.microsoft.com/kb/829743" target="_blank">We
even have a KB article that discusses this issue somewhat</a>.  
</p>
        <h3>The Fix
</h3>
        <p>
Fortunately, the fix is pretty simple.  
</p>
        <p>
First, we need to store the path to the User Control instead of the AQN in ViewState. 
To do this, you can comment out the “typeName = ….” line from directly above and replace
it with:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <br />
UserControl uc = control <span style="color: #0000ff">as</span> UserControl;<br />
typeName = <span style="color: #006080">"UC:"</span> + uc.AppRelativeVirtualPath;</pre>
          <br />
        </div>
        <p>
So, now we store the path to the UserControl in ViewState.  Then, we need to
fix the code that actually loads the control.  Replace the code from above in
the RestoreChildStructure(…) method with this code:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <br />
            <span style="color: #0000ff">string</span> path = typeName[1];<br /><br /><span style="color: #0000ff">try</span><br />
{<br />
control = Page.LoadControl(path);<br />
}<br /><span style="color: #0000ff">catch</span> (Exception e)<br />
{<br /><span style="color: #0000ff">throw</span><span style="color: #0000ff">new</span> ArgumentException(String.Format(<br /><span style="color: #006080">"The type '{0}' cannot be recreated from ViewState"</span>, 
<br />
path), e);<br />
}</pre>
          <br />
        </div>
        <p>
That’s all there is to it.  Just load the user control from where it is being
stored in the site and ASP.NET will take care of loading the appropriate assembly.
</p>
        <p>
Enjoy!
</p>
      </body>
      <title>Fixing the DynamicControlsPlaceholder control – Making the community better</title>
      <guid isPermaLink="false">http://www.samuraiprogrammer.com/blog/PermaLink,guid,7e3dbca2-67a5-43c1-91d9-af075409b9c9.aspx</guid>
      <link>http://www.samuraiprogrammer.com/blog/2010/08/14/FixingTheDynamicControlsPlaceholderControlMakingTheCommunityBetter.aspx</link>
      <pubDate>Sat, 14 Aug 2010 17:45:39 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/2010/07/29/AreYouReadyForYourNextChallengeWereHiring.aspx" target="_blank"&gt;&lt;img style="border-right-width: 0px; margin: 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="11954221481914068549johnny_automatic_mister_fix_it_svg_hi" border="0" alt="11954221481914068549johnny_automatic_mister_fix_it_svg_hi" align="left" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/FixingtheDynamicControlsPlaceholdercontr_1B28/11954221481914068549johnny_automatic_mister_fix_it_svg_hi_8904f347-29ea-413f-bb83-420c018312a1.png" width="124" height="114" /&gt; In
my job as a PFE&lt;/a&gt; for &lt;a href="http://www.microsoft.com"&gt;Microsoft&lt;/a&gt;, I read,
review and fix a lot of code.&amp;#160; A lot of code.&amp;#160; It’s a large part of what
I love about my job.&amp;#160; The code is generally written by large corporations or &lt;a href="http://www.codinghorror.com/blog/2008/12/the-problem-with-logging.html" target="_blank"&gt;for
public websites&lt;/a&gt;.&amp;#160; Every now and again I’ll get pinged on an issue and after
troubleshooting the issue, it’s pretty clear that the core issue is with some community
code.&amp;#160; When I say community code, in this instance, I don’t mean a CodeProject
or CodePlex project.&amp;#160; In this case, I am referring to a control that &lt;a href="http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx" target="_blank"&gt;Denis
Bauer created and then made available to the community on his website – the “DynamicControlsPlaceholder”
control&lt;/a&gt;.&amp;#160; This is a great little control that inherits from a PlaceHolder
and allows you to&amp;#160; create dynamic controls on the fly and then it will persist
the controls you add on subsequent requests – like a postback.
&lt;/p&gt;
&lt;h3&gt;The Problem
&lt;/h3&gt;
&lt;p&gt;
The customer was experiencing a problem that could only be replicated in a web farm
when they don’t turn on &lt;a href="http://stackoverflow.com/questions/1040025/difference-between-session-affinity-and-sticky-session" target="_blank"&gt;sticky
sessions&lt;/a&gt;.&amp;#160; They found that when a request went from one server to another
server in their farm they would get a FileNotFoundException with the following details:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;Type Of Exception:FileNotFoundException&lt;br /&gt;
Message:Error on page http://blahblahblah.aspx&lt;br /&gt;
Exception Information:System.IO.FileNotFoundException: 
&lt;br /&gt;
Could not load file or assembly 'App_Web_myusercontrol.ascx.cc671b29.ypmqvhaw, 
&lt;br /&gt;
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. 
&lt;br /&gt;
The system cannot find the file specified.&lt;br /&gt;
File name: 'App_Web_myusercontrol.ascx.cc671b29.ypmqvhaw, 
&lt;br /&gt;
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'&lt;br /&gt;
at System.RuntimeTypeHandle.GetTypeByName(String name, 
&lt;br /&gt;
Boolean throwOnError, 
&lt;br /&gt;
Boolean ignoreCase, 
&lt;br /&gt;
Boolean reflectionOnly, 
&lt;br /&gt;
StackCrawlMark&amp;amp; stackMark)&lt;br /&gt;
...&lt;br /&gt;
at DynamicControlsPlaceholder.RestoreChildStructure(Pair persistInfo, 
&lt;br /&gt;
Control parent)&lt;br /&gt;
at DynamicControlsPlaceholder.LoadViewState(Object savedState) 
&lt;br /&gt;
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)&lt;br /&gt;
...&lt;br /&gt;
at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)&lt;br /&gt;
at System.Web.UI.Page.LoadAllState()&lt;br /&gt;
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, 
&lt;br /&gt;
Boolean includeStagesAfterAsyncPoint)&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
So, we can gleam a few things from the error details:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
They are using the ASP.NET website model (the “app_web_….dll” assembly is the clue). 
&lt;/li&gt;
&lt;li&gt;
The error is occurring in the RestoreChildStructure method of the DynamicControlsPlaceholder
control. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;The Research
&lt;/h3&gt;
&lt;p&gt;
The way that ASP.NET Websites work is that each component of your site can be compiled
into a separate assembly.&amp;#160; The assembly name is randomly generated.&amp;#160; This
also means that on two servers, the name of the assemblies can end up being different.&amp;#160;
So, an assumption to make is that something is trying to load an assembly by its name.&amp;#160;
If we look at the RestoreChildStructure method, we see the following:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
&lt;br /&gt;
Type ucType = Type.GetType(typeName[1], &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
MethodInfo mi = &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Page).GetMethod(&lt;span style="color: #006080"&gt;&amp;quot;LoadControl&amp;quot;&lt;/span&gt;, 
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Type[2] { &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Type), &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[])
});&lt;br /&gt;
control = (Control) mi.Invoke(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Page, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[2]
{ ucType, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; });&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception e)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentException(String.Format(&lt;span style="color: #006080"&gt;&amp;quot;The
type '{0}' …&amp;quot;&lt;/span&gt;, 
&lt;br /&gt;
ucType.ToString()), e);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
The important thing to look at here is the Type.GetType(…) call.&amp;#160; Since the code
for the control is in a separate assembly from everything else, the “typeName[1]”
value &lt;strong&gt;MUST BE A FULLY QUALIFIED ASSEMBLY NAME&lt;/strong&gt;.&amp;#160; From the exception
details, we can see that it is attempting to load the type from the following string:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;App_Web_myusercontrol.ascx.cc671b29.ypmqvhaw, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null&lt;/strong&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The “typeName[1]” variable is loaded from ViewState because that’s where the control
persists its child structure.&amp;#160; So, for some reason the fully qualified assembly
name is stored in ViewState.&amp;#160; If we look at the code that inserts the value into
ViewState (in the PersistChildStructure(…) method), we see:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
&lt;br /&gt;
typeName = &lt;span style="color: #006080"&gt;&amp;quot;UC:&amp;quot;&lt;/span&gt; + control.GetType().AssemblyQualifiedName; &lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
So, here we see the AssemblyQualifiedName is being stored into ViewState – which is
then used to persist the controls across postback using the above code.&amp;#160; As I
mentioned, this won’t work with an ASP.NET website hosted in a web farm because the
assembly qualified name will probably be different from server to server.&amp;#160; &lt;a href="http://support.microsoft.com/kb/829743" target="_blank"&gt;We
even have a KB article that discusses this issue somewhat&lt;/a&gt;.&amp;#160; 
&lt;/p&gt;
&lt;h3&gt;The Fix
&lt;/h3&gt;
&lt;p&gt;
Fortunately, the fix is pretty simple.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
First, we need to store the path to the User Control instead of the AQN in ViewState.&amp;#160;
To do this, you can comment out the “typeName = ….” line from directly above and replace
it with:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
&lt;br /&gt;
UserControl uc = control &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; UserControl;&lt;br /&gt;
typeName = &lt;span style="color: #006080"&gt;&amp;quot;UC:&amp;quot;&lt;/span&gt; + uc.AppRelativeVirtualPath;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
So, now we store the path to the UserControl in ViewState.&amp;#160; Then, we need to
fix the code that actually loads the control.&amp;#160; Replace the code from above in
the RestoreChildStructure(…) method with this code:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; path = typeName[1];&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;try&lt;/span&gt;
&lt;br /&gt;
{&lt;br /&gt;
control = Page.LoadControl(path);&lt;br /&gt;
}&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception e)&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentException(String.Format(&lt;br /&gt;
&lt;span style="color: #006080"&gt;&amp;quot;The type '{0}' cannot be recreated from ViewState&amp;quot;&lt;/span&gt;, 
&lt;br /&gt;
path), e);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
That’s all there is to it.&amp;#160; Just load the user control from where it is being
stored in the site and ASP.NET will take care of loading the appropriate assembly.
&lt;/p&gt;
&lt;p&gt;
Enjoy!
&lt;/p&gt;</description>
      <comments>http://www.samuraiprogrammer.com/blog/CommentView,guid,7e3dbca2-67a5-43c1-91d9-af075409b9c9.aspx</comments>
      <category>ASP.NET</category>
      <category>Development</category>
      <category>Premier Field Engineer (PFE)</category>
    </item>
    <item>
      <trackback:ping>http://www.samuraiprogrammer.com/blog/Trackback.aspx?guid=dc55e7ac-8adf-4d2d-bc3f-9d4eef37734d</trackback:ping>
      <pingback:server>http://www.samuraiprogrammer.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.samuraiprogrammer.com/blog/PermaLink,guid,dc55e7ac-8adf-4d2d-bc3f-9d4eef37734d.aspx</pingback:target>
      <dc:creator>Greg Varveris</dc:creator>
      <wfw:comment>http://www.samuraiprogrammer.com/blog/CommentView,guid,dc55e7ac-8adf-4d2d-bc3f-9d4eef37734d.aspx</wfw:comment>
      <wfw:commentRss>http://www.samuraiprogrammer.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=dc55e7ac-8adf-4d2d-bc3f-9d4eef37734d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/mslogo-1_2.jpg">
            <img style="border-right-width: 0px; margin: 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="mslogo-1" border="0" alt="mslogo-1" align="right" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/mslogo-1_thumb.jpg" width="240" height="53" />
          </a> First,
a few questions:
</p>
        <ul>
          <li>
Do you enjoy helping developers write better code? 
<br /></li>
          <li>
Do you enjoy solving complex problems that span multiple technologies? 
<br /></li>
          <li>
Do you enjoy optimizing and improving code? 
<br /></li>
          <li>
Are you passionate about software development? 
<br /></li>
          <li>
Do you enjoy managing your own calendar? 
<br /></li>
          <li>
Do you want to make the world a better place? 
</li>
        </ul>
        <p>
If the answer to these questions is “YES!”, then please read-on. 
</p>
        <p>
          <a href="https://careers.microsoft.com/Search.aspx#&amp;&amp;p4=US&amp;p0=premier+field+engineer&amp;p5=all&amp;p1=37&amp;p2=1003&amp;p3=all" target="_blank">We
are now actively recruiting for 3 Developer Premier Field Engineering positions at
Microsoft</a>.  
</p>
        <p>
You may ask yourself, what does a Dev PFE do?<a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/net_v_web_2.jpg"><img style="border-right-width: 0px; margin: 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="net_v_web" border="0" alt="net_v_web" align="right" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/net_v_web_thumb.jpg" width="118" height="113" /></a></p>
        <p>
We do both proactive and reactive work encompassing a variety of <a href="http://www.microsoft.com">Microsoft</a>’s
developer products.  In general, the reactive work is where a customer is experiencing
a problem (usually in production) and they need someone onsite to help them resolve
the issue. The proactive work usually takes the form of knowledge transfer to companies
on how they can improve the maintainability of their code, how to debug problems and
how to optimize their applications.  I have also done a fair number of “proofs
of concept” for customers where they just don’t know how to do something or they want
me to prove that it can be done.  
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/microsoftbizcard219border333-thumb_2.jpg">
            <img style="border-right-width: 0px; margin: 0px 10px 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="microsoftbizcard219border333-thumb" border="0" alt="microsoftbizcard219border333-thumb" align="left" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/microsoftbizcard219border333-thumb_thumb.jpg" width="199" height="124" />
          </a>In
the past year, I’ve worked on projects using <a href="http://www.microsoft.com/net/" target="_blank">.NET
(1.1 – 4.0)</a>, <a href="http://www.microsoft.com/windowsazure/windowsazure/" target="_blank">Windows
Azure</a>, <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" target="_blank">Internet
Explorer</a>, <a href="http://www.bing.com" target="_blank">Bing</a>, <a href="http://translate.bing.com" target="_blank">Bing
Translator</a>, <a href="http://www.microsoft.com/windows/windows-7/default.aspx" target="_blank">Windows
7</a> and many others.  
</p>
        <p>
And the list really does go on.  You will work with our largest customers around
the world helping them write better code, solving complex issues, teaching them about
the latest technology and just making the world a better place.
</p>
        <p>
If this sounds like a good fit for you, <a href="https://careers.microsoft.com/Search.aspx#&amp;&amp;p4=US&amp;p0=premier+field+engineer&amp;p5=all&amp;p1=37&amp;p2=1003&amp;p3=all" target="_blank">click
here to go to the Microsoft Careers site to apply</a>.
</p>
      </body>
      <title>Are you ready for your next challenge? (We’re hiring!)</title>
      <guid isPermaLink="false">http://www.samuraiprogrammer.com/blog/PermaLink,guid,dc55e7ac-8adf-4d2d-bc3f-9d4eef37734d.aspx</guid>
      <link>http://www.samuraiprogrammer.com/blog/2010/07/29/AreYouReadyForYourNextChallengeWereHiring.aspx</link>
      <pubDate>Thu, 29 Jul 2010 21:21:57 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/mslogo-1_2.jpg"&gt;&lt;img style="border-right-width: 0px; margin: 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="mslogo-1" border="0" alt="mslogo-1" align="right" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/mslogo-1_thumb.jpg" width="240" height="53" /&gt;&lt;/a&gt; First,
a few questions:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Do you enjoy helping developers write better code? 
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
Do you enjoy solving complex problems that span multiple technologies? 
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
Do you enjoy optimizing and improving code? 
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
Are you passionate about software development? 
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
Do you enjoy managing your own calendar? 
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
Do you want to make the world a better place? 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
If the answer to these questions is “YES!”, then please read-on. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="https://careers.microsoft.com/Search.aspx#&amp;amp;&amp;amp;p4=US&amp;amp;p0=premier+field+engineer&amp;amp;p5=all&amp;amp;p1=37&amp;amp;p2=1003&amp;amp;p3=all" target="_blank"&gt;We
are now actively recruiting for 3 Developer Premier Field Engineering positions at
Microsoft&lt;/a&gt;.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
You may ask yourself, what does a Dev PFE do?&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/net_v_web_2.jpg"&gt;&lt;img style="border-right-width: 0px; margin: 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="net_v_web" border="0" alt="net_v_web" align="right" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/net_v_web_thumb.jpg" width="118" height="113" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We do both proactive and reactive work encompassing a variety of &lt;a href="http://www.microsoft.com"&gt;Microsoft&lt;/a&gt;’s
developer products.&amp;#160; In general, the reactive work is where a customer is experiencing
a problem (usually in production) and they need someone onsite to help them resolve
the issue. The proactive work usually takes the form of knowledge transfer to companies
on how they can improve the maintainability of their code, how to debug problems and
how to optimize their applications.&amp;#160; I have also done a fair number of “proofs
of concept” for customers where they just don’t know how to do something or they want
me to prove that it can be done.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/microsoftbizcard219border333-thumb_2.jpg"&gt;&lt;img style="border-right-width: 0px; margin: 0px 10px 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="microsoftbizcard219border333-thumb" border="0" alt="microsoftbizcard219border333-thumb" align="left" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/AreyoureadyforyournextchallengeWerehirin_E14B/microsoftbizcard219border333-thumb_thumb.jpg" width="199" height="124" /&gt;&lt;/a&gt;In
the past year, I’ve worked on projects using &lt;a href="http://www.microsoft.com/net/" target="_blank"&gt;.NET
(1.1 – 4.0)&lt;/a&gt;, &lt;a href="http://www.microsoft.com/windowsazure/windowsazure/" target="_blank"&gt;Windows
Azure&lt;/a&gt;, &lt;a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" target="_blank"&gt;Internet
Explorer&lt;/a&gt;, &lt;a href="http://www.bing.com" target="_blank"&gt;Bing&lt;/a&gt;, &lt;a href="http://translate.bing.com" target="_blank"&gt;Bing
Translator&lt;/a&gt;, &lt;a href="http://www.microsoft.com/windows/windows-7/default.aspx" target="_blank"&gt;Windows
7&lt;/a&gt; and many others.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
And the list really does go on.&amp;#160; You will work with our largest customers around
the world helping them write better code, solving complex issues, teaching them about
the latest technology and just making the world a better place.
&lt;/p&gt;
&lt;p&gt;
If this sounds like a good fit for you, &lt;a href="https://careers.microsoft.com/Search.aspx#&amp;amp;&amp;amp;p4=US&amp;amp;p0=premier+field+engineer&amp;amp;p5=all&amp;amp;p1=37&amp;amp;p2=1003&amp;amp;p3=all" target="_blank"&gt;click
here to go to the Microsoft Careers site to apply&lt;/a&gt;.
&lt;/p&gt;</description>
      <comments>http://www.samuraiprogrammer.com/blog/CommentView,guid,dc55e7ac-8adf-4d2d-bc3f-9d4eef37734d.aspx</comments>
      <category>Hiring</category>
      <category>Microsoft</category>
      <category>Premier Field Engineer (PFE)</category>
    </item>
  </channel>
</rss>