RegisterClientScriptResource NullReferenceException in a Child IIS Application

烂漫一生 提交于 2019-12-11 03:32:27

问题


I upgraded from .Net 4.5 Beta to the RTM version, and now when I have a standard WebForm page where I had a generic <asp:RequiredFieldValidator /> tag I get a NullReferenceException that looks like this:

[NullReferenceException: Object reference not set to an instance of an object.] System.Web.UI.WebControls.ValidatorCompatibilityHelper.RegisterClientScriptResource(Control control, String resourceName) +180 System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +253 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +255 System.Web.UI.Control.PreRenderRecursiveInternal() +255 System.Web.UI.Control.PreRenderRecursiveInternal() +255 System.Web.UI.Control.PreRenderRecursiveInternal() +255 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4047

I even created a sample page (no master pages - just the below HTML) and as soon as I add the validator I get the above error. Here is it's HTML:

<form runat="server">
     <asp:Textbox runat="server" ID="txTest" />
     <asp:RequiredFieldValidator runat="server" ControlToValidate="txTest" />
</form>

Other pages for other sites on this server work fine, so I'm suspecting this is related to it being a sub application within IIS and the parent app is Orchard. Any suggestions on how I might resolve this? Since it's just a standard tag I don't even know where to start looking.

Edit: I figured out what was causing it to break, though I'm hoping someone from the Orchard team could clarify why this was done. Inside the default config there is a section under compilation for assemblies and inside that there is a number of assemblies that are removed. I took the whole list out and my inner page worked so I started adding them in one at a time and it broke when I added the remove entry for System.Web.Extensions. I can easily add it in to my child app, but I'm curious as to why it would've been removed in the first place. Here is what it typically looks like and I removed the entry for System.Web.Extensions to make my child app work:

    <compilation debug="false" targetFramework="4.0" batch="true" numRecompilesBeforeAppRestart="250" optimizeCompilations="true">
  <buildProviders>
    <add extension=".csproj" type="Orchard.Environment.Extensions.Compilers.CSharpExtensionBuildProviderShim" />
  </buildProviders>
  <assemblies>
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <remove assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <remove assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <remove assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <remove assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <remove assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <remove assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <remove assembly="System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <remove assembly="System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <remove assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <remove assembly="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <remove assembly="System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <remove assembly="System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <remove assembly="System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <remove assembly="System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <remove assembly="System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <remove assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <remove assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <remove assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </assemblies>
</compilation>

回答1:


In Orchard's web.config, some assemblies are explicitly removed as they are not used by Orchard itself. If you need them then it's safe to re-enable them.



来源:https://stackoverflow.com/questions/13638627/registerclientscriptresource-nullreferenceexception-in-a-child-iis-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!