Strange exception with .NET 4 - 'SecurityRulesAttribute' does not exist in the namespace 'System.Security'

Proposed Strange exception with .NET 4 - 'SecurityRulesAttribute' does not exist in the namespace 'System.Security'

  • Friday, July 30, 2010 1:34 PM
     
      Has Code

    I get a very strange exception on a ASP.NET 4.0 site with IIS in Windows Server 2008 -

     

    The type or namespace name 'SecurityRulesAttribute' does not exist in the namespace 'System.Security' (are you missing an assembly reference?) 

     

    The stack trace doesn't give any useful information:

     

    [XslLoadException: The type or namespace name 'SecurityRulesAttribute' does not exist in the namespace 'System.Security' (are you missing an assembly reference?)]

       System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) +1226517

     

    It happens when I try to do a XSL Transformation (using XslCompiledTransform):

     

     

    xslt.Load(xslStreamDoc, settings, new XmlUrlResolver());

     

    I checked the assembly references and they are all pointing to 4.0 (System.Xml, mscorlib, etc.). I verified that the SecurityRulesAttribute class exists in mscorlib 4.0. The weird thing is that the problem does not happen if I run the web site using the ASP.NET Development server in VS 2010.

     

    The site runs fine in IIS with the exception of the above XSLT. Any ideas?

     

    • Edited by lingvomir Friday, July 30, 2010 1:35 PM tinyMCE MS Word stripping problem
    • Moved by SamAgain Thursday, August 05, 2010 9:26 AM (From:Common Language Runtime)
    •  

All Replies

  • Friday, July 30, 2010 7:59 PM
     
     Proposed
    Are you absolutely sure that this ASP app is configured to run with 4.0? 
    Phil Wilson
    • Proposed As Answer by Matthew N Tuesday, August 03, 2010 7:53 AM
    •  
  • Tuesday, August 03, 2010 7:55 AM
     
     Proposed

    I got this error too using almost exactly the same code. It appears there are a few traps. Here is what I did:

    1. Ensure that the following command is run to install the Framework 4 ISAPI filter on IIS:

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe /i

    2. Ensure that the iis server is indeed being called via the default website and default app pool. Also, as previously noted, ensure that the web site is building using .Net 4 Framework

    3. Ensure that the Default App Pool is using Framework 2 (not 4) if the web.config file in the web site is meant to use that schema. From there ensure that the default website is using that default app pool

    4. Ensure the ISAPI and CGI Restrictions ALLOW the .Net 4 ISAPI Filter (its off by default after installation) for the web server

    5. You don't need the Framework 4 version of the mscorlib file in the bin folder and you can't put it in the GAC. The web site will find it if the steps above are followed.

    It took a while but I was methodical.

    -Matthew Newbery

    • Proposed As Answer by Matthew N Tuesday, August 03, 2010 7:55 AM
    •  
  • Thursday, August 05, 2010 9:26 AM
     
     

    Hi,

      Thanks for your post. Please consider http://forums.asp.net as a better option.


    Please mark the right answer at right time.
    Thanks,
    Sam