I ran into the same error, not sure if its the same thing... But i found that my code was throwing an exception. Tried some exception handling when i found the error it had nothing to do with the error that was reported.

"must be compiled with the AllowPartiallyTrustedCallersAttribute set to succeed"

Well in my code i was attempting to access a web service in the constructor and apparently no permissions are granted at this point. Changed the code to run in the CreateChildControls and like magic it worked....

Hope this helps