none
System.Security.Policy.PolicyException: Required permissions cannot be acquired. RRS feed

  • Question

  • Good Morning

    I am currently having issues with a website that we are attempting to create which calls files from several locations. One of the developers is able to access the information on VS2013, but I am unable to do so on VS2017

    I continue to have the following 2 issues:

    When opening the page on the browsers I get the following:

    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) +7627571
       System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57
    
    [FileLoadException: Could not load file or assembly 'Oracle.DataAccess, Version=2.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
       System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
       System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
       System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
       System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
       System.Reflection.Assembly.Load(String assemblyString) +28
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46
    
    [ConfigurationErrorsException: Could not load file or assembly 'Oracle.DataAccess, Version=2.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
       System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
       System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
       System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
       System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
       System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +600
       System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125
       System.Web.Compilation.BuildManager.CompileCodeDirectories() +265
       System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +320
    
    [HttpException (0x80004005): Could not load file or assembly 'Oracle.DataAccess, Version=2.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
       System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
       System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729
    
    [HttpException (0x80004005): Could not load file or assembly 'Oracle.DataAccess, Version=2.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9002835
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333

    When I attempt to open one of the Servers links I get:

    Attempt to load Oracle client libraries threw BadImageFormatExemption. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.

    Measures taken trying to resolve the issue by our IT department:

    • Download and install Oracle x86 Client, for example into C:\Oracle\12.2\Client86_1
    • Download and install Oracle x64 Client into different folder, for example to C:\Oracle\12.2\Client64_1
    • Open command line tool, go to folder %WINDIR%\System32, typically C:\Windows\System32 and create a symbolic link ora122 to folder C:\Oracle\12.2\Client_x64 (see commands section below)
    • Change to folder %WINDIR%\SysWOW64, typically C:\Windows\SysWOW64 and create a symbolic link ora112 to folder C:\Oracle\12.2\Client_x86, (see below)
    • Modify the PATH environment variable, replace all entries like C:\Oracle\12.2\Client32_1 and C:\Oracle\12.2\Client64_1 by C:\Windows\System32\ora122, respective their \bin subfolder. Note: C:\Windows\SysWOW64\ora122 must not be in PATH environment.
    • If needed set your ORACLE_HOME environment variable to C:\Windows\System32\ora122
    • Open your Registry Editor. Set Registry value HKLM\Software\ORACLE\KEY_OraClient12.2_home1\ORACLE_HOME to C:\Windows\System32\ora122
    • Set Registry value HKLM\Software\Wow6432Node\ORACLE\KEY_OraClient12.2_home1\ORACLE_HOME to C:\Windows\System32\ora122 (not C:\Windows\SysWOW64\ora122)
    • You are done! Now you can use x86 and x64 Oracle client seamless together, i.e. an x86 application will load the x86 libraries, an x64 application loads the x64 libraries without any further modification on your system.

    Not sure where to go from here. Can anyone please help?

    Thursday, September 12, 2019 12:55 PM

All replies

  • Since you're using .NETv4, I'm assuming you're not affected by CAS settings. More on that here if you're on the "still applicable to you" side.

    In your IIS application pool advanced settings, under "Process Model", try set "Load User Profile" to true. Some reported they got this PolicyException when the user profile is not loaded. See if this settings can fix it.

    EDIT: Reading the source code of the method throwing this exception, I think Oracle.DataAccess is compiled with CAS policy checking enabled, and you should try troubleshoot the setting with caspol.exe as mentioned in here.

    If you want to turn off CAS completely (afterall we're walking away from CAS in .NET v4+), try run "caspol -s off". This will disable CAS for the current machine. (note that you need to run caspol in Framework64 folder (say, Windows\Microsoft.NET\Framework64\v4.0.30319) to disable it for 64bit runtime. 32bit and 64bit policy is controlled sepereately)

    EDIT2: Looks like the "-s" and "-e" switches are removed from .NET v4 caspol.exe. Check with "caspol -list" and see if it affects you first.





    Friday, September 13, 2019 1:50 AM
    Answerer