I'm using FileHelpers for reading csv files, and all it was ok until I switched from VS dev server to IIS, I get a "PolicyException: Required permissions cannot be acquired", I googled and found that I need to add Reflection Permission for this to work, anybody knows how ?
2 Answers
It sounds like you're running in partial trust. If your production environment is running in full trust, just update your dev environment to run in full trust. However, if you're trying to simulate your production environment, then here's how to change it:
Go to your framework folder/config. Find out which trust level you're on. i.e. medium, full, etc. That may be set in your site's web.config, or the framework's root web.config.
Whatever you do in dev, you'll need to do in production to. So the first step is to setup your dev like production. Then, if production is medium trust (for example), you'll need to either update the web_mediumtrust.config file or create a copy of it as a custom policy. Use the syntax in the root web.config file to see how to define it. Search for keyword 'trust'.
Add the following to your trust template:
In the <SecurityClasses>
section:
<SecurityClass Name="ReflectionPermission" Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
In the <PermissionSet class=NamedPermissionSet ..>
section, add either something like this:
<IPermission
class="ReflectionPermission"
version="1"
Flags="ReflectionEmit"
/>
where Flags is a comma delimited list of specific permissions.
or:
<IPermission
class="ReflectionPermission"
version="1"
Unrestricted="true"
/>
Make sure to get approval to have the same settings pushed to production too.
-
I know that this should work, but it doesn't for me, I'm on my local IIS, and I have set a Full trust level, and I still get this error– OmuCommented Dec 5, 2009 at 8:00
-
You shouldn't get that in full trust. My guess is that something in your .config path or code is setting the trust level. Can you include the full error message just in case there are extra hints from it? Commented Dec 5, 2009 at 15:37
-
it was the Load User Profile property from DefaultAppPool AdvanceSettings, I had to set it to true.– OmuCommented Dec 7, 2009 at 7:36
-
no, sorry, it wasn't, it was something else, probably i was using some wrong dlls or i was referencing different dlls (instead of the same) in different assemblys– OmuCommented Dec 7, 2009 at 9:25
-
nope, it wasn't this either, but the answer is correct for this specific question, so I'm gonna ask another question– OmuCommented Dec 11, 2009 at 10:02
Is any of the assembly you use located on a network share? If yes than:
- Move them to the local machine.
or - Use "Microsoft .NET Framework 2.0 Configuration" to grant full trust to local intranet.
-
it was the Load User Profile property from DefaultAppPool AdvanceSettings, I had to set it to true.– OmuCommented Dec 7, 2009 at 7:50