title: Null reference exception in WriteAttributeTo method
body: <p>The following code gives a NULL reference error when str is NULL, but only on our production server, not on our development or testing servers.</p>
  
  <pre><code>&lt;div&gt;
  &lt;input value="@Html.Raw(str)" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This works just fine:</p>
  
  <pre><code>&lt;div&gt;
  &lt;input value="@str" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>As does this:</p>
  
  <pre><code>&lt;div&gt;
  Values is: @Html.Raw(str)
  &lt;/div&gt;
  </code></pre>
  
  <p>So it's not an issue of @Html.Raw not being able to accept a NULL parameter. I'm not sure what exactly it returns in that case though; but it's somehow different on one server than on another.</p>
  
  <p>Both are running the same version of System.Web.Mvc, though I don't know know what other DLLs to check. System.Web.WebPages, which is the assembly that should contain the MVC method that's crashing, is the same version on both servers. This is MVC version 4; .Net 4.5.</p>
  
  <p>How is such a thing possible? The error occurs in the WriteAttributeTo method, though I don't even know why that would be called here, since it's using standard HTML input tags, not the @Html.TextBoxFor helper.</p>
  
  <p><em>Edit</em>
  One thing that might be helpful is if others try putting that code in a View of their own to see if it works or breaks. At least then I would know if it's my production environment or the testing environment that's behaving unexpectedly.</p>
  
  <p>Here is the full stack trace:</p>
  
  <blockquote>
    <p>at System.Web.WebPages.WebPageExecutingBase.WriteAttributeTo(String
    pageVirtualPath, TextWriter writer, String name, PositionTagged<code>1
    prefix, PositionTagged</code>1 suffix, AttributeValue[] values) at
    System.Web.WebPages.WebPageExecutingBase.WriteAttributeTo(TextWriter
    writer, String name, PositionTagged<code>1 prefix, PositionTagged</code>1 suffix,
    AttributeValue[] values) at
    System.Web.WebPages.WebPageExecutingBase.WriteAttribute(String name,
    PositionTagged<code>1 prefix, PositionTagged</code>1 suffix, AttributeValue[]
    values) at ASP._Page_Views_AdminSurvey_TopDown_cshtml.Execute() in
    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
    Files\root\fdd62ffd\90d151d1\App_Web_xsolwitr.2.cs:line 0 at
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at
    System.Web.WebPages.StartPage.ExecutePageHierarchy() at
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext
    pageContext, TextWriter writer, WebPageRenderingBase startPage) at
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
    at
    System.Web.Mvc.ControllerActionInvoker.&lt;>c_<em>DisplayClass1a.b</em>_17()
    at
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter
    filter, ResultExecutingContext preContext, Func<code>1 continuation) at
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter
    filter, ResultExecutingContext preContext, Func</code>1 continuation) at
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext
    controllerContext, IList`1 filters, ActionResult actionResult) at
    System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;>c_<em>DisplayClass25.b</em>_22(IAsyncResult
    asyncResult) at
    System.Web.Mvc.Controller.&lt;>c_<em>DisplayClass1d.b</em>_18(IAsyncResult
    asyncResult) at
    System.Web.Mvc.Async.AsyncResultWrapper.&lt;>c_<em>DisplayClass4.b</em>_3(IAsyncResult
    ar) at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult
    asyncResult) at
    System.Web.Mvc.Async.AsyncResultWrapper.&lt;>c_<em>DisplayClass4.b</em>_3(IAsyncResult
    ar) at
    System.Web.Mvc.MvcHandler.&lt;>c_<em>DisplayClass6.&lt;>c</em>_DisplayClassb.b_<em>4(IAsyncResult
    asyncResult) at
    System.Web.Mvc.Async.AsyncResultWrapper.&lt;>c</em>_DisplayClass4.b__3(IAsyncResult
    ar) at
    System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    Boolean&amp; completedSynchronously)</p>
  </blockquote>