Security Exception when trying to run Compress.

May 11, 2010 at 10:18 AM
Edited May 11, 2010 at 10:21 AM

I get this error when I try to use YUI Compressor.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Here's the code.

string rsp = "function addLoadEvent(func) {\n"+
"    var o = window.onload; \n"+
"    if (typeof window.onload != 'function') { \n"+
"        window.onload = func; \n"+
"    } else { \n"+
"        window.onload = function() { \n"+
"	        if (o) { \n"+
"	            o(); \n"+
"            } \n"+
"            func(); \n"+
"        } \n"+
"    } \n" +
"}";


string compressedJavaScript = JavaScriptCompressor.Compress(rsp);

It fails on JavaScriptCompressor.Compress(rsp);

I'm using the .Net 2.0 version of 1.4.1.0 - Raptor.

I'm running this off my local development machine, windows 7, IIS 7.

All 3 DLLs are in my 3rd party dependencies folder, and a reference to the Yahoo.Yui.Compressor.NET20.dll is on the project. It builds OK.

I have tried adding

[assembly: System.Security.AllowPartiallyTrustedCallers()]
[assembly: System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.RequestMinimum, Name = "FullTrust")]

and it makes no difference.

My web.config has the trust level set to full as well.

May 11, 2010 at 3:33 PM
Solved my own problem. I needed [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)] after any namespace in which this was used. I have no idea why.