I have been using the Microsoft Enterprise Library for many years now. For the first time, I had serious problems deploying them to a production environment today. After about an hour of searching online, I found out that a lot of people were having this problem and only a few people had figured out how to resolve it. Here's what I did....very easy, very fast.
Problem:Deployed web application with any Microsoft Enterprise Library component and received the follow error:
Server Error in '/' Application
Required permissions cannot be acquired.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Policy.PolicyException: Required permissions cannot be acquired.
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: [PolicyException: Required permissions cannot be acquired.] System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +2736869 System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57
blah blah blah... |
Explanation:Simply put, the Microsoft Enterprise Library is trying to perform operations that it is not allowed based on the trust level set on that server.
I have never received this error before since I host all of my code on my own dedicated servers (where I have a "Full" trust set).
Recently, I have been opening accounts for customers at WebHost4Life.com (I'm sort of trying to get out of the hosting business due to the liabilities). WebHost4Life must also have the trust level set to "Full" since I've never had problems there. Just today, I deployed code to a new hosting provider. I believe they have their trust level set to "Medium" and this is why I'm getting the error.
Resolution:1. A few months ago, Microsoft released updated code to resolve this issue.
Click here to download the code updates2. For any application block to read information from configuration files, it is necessary to grant the application ConfigurationPermission (which is not provided by default in medium trust). You can add the requirePermission="false" attribute to the application's configuration section definitions. For example:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="dataConfiguration" requirePermission="false"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data"/>
</configSections>
.
.
.
</configuration>
That's it...pretty easy and fast.
Comments
Leave a Comment