0

i have a website that up and running. today, as usual, i did a simple change in the Service, re-compiled it and upload it to production. then, i got a strange Security Exception saying:

Server Error in '/' Application.

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.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +31
   System.Security.CodeAccessPermission.Demand() +46
   System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Module m, StackCrawlMark& stackMark, Boolean skipVisibility) +248
   System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Module m, Boolean skipVisibility) +49
   System.Runtime.Serialization.CodeGenerator.BeginMethod(Type returnType, String methodName, Type[] argTypes, Boolean allowPrivateMemberAccess) +53
   System.Runtime.Serialization.CodeGenerator.BeginMethod(String methodName, Type delegateType, Boolean allowPrivateMemberAccess) +131
   System.Runtime.Serialization.CriticalHelper.GenerateClassReader(ClassDataContract classContract) +141

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

I looked for a solution, and found many links but neither of them worked. i have no clue where this bug came from, out of nowhere... just for your information - the change was just adding a field to entity framework.

after 6 hours i gave up and posted here the problem.

any ideas?

2 Answers 2

2

It is not a bug. Probably you try to run the application that requires FullTrust on the hosting that only allows PartialTrust.

Especially with WCF, some of the bindings (like NetTCP) just do not support partial trust level and require a full trust one.

So you need to know which trust level is required by your application and then make it happen on your servers :)

1
  • i don't know what "trust level" is. especially because i never use this attribute.
    – Yaniv
    Feb 12, 2012 at 6:10
1

i found the answer for my case !

i made 2 changes in my WCF that did the trick, so i dont know exactly what solve it, but it may be the mix of them:

  1. first, i've noticed that the new field that i added what configured to "throw exception" on NULL values. it very important to change it to "empty" so the service wont throw any exception in that case. but the error message doesn't fit to this error, as "null error" would be excepted.

  2. the other thing that i've done is - getting the DataTable from a Stored Procedure and not as "hard coded" sql statement.

it seems to me that the latter did the trick, as it seem to me more related to security issue, but it is just an assumption, as the first step was very important step to do.

that's all. it works now, thank you for your reply, hope my answer will help someone sometime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.