2009-12-08 64 views
0

我的解決方案中的2個類庫(Dto和Services)中引用了FileHelpers.dll(2.0)
我的webapp(asp.net mvc)位於IIS7完全信任)Windows 7 PRO 64和我有時從VS2008啓動我的應用程序時出現此異常: (爲了擺脫它,我從bin中刪除FileHelpers.dll,運行,關閉瀏覽器,重新生成解決方案並再次運行)錯誤;有時:S:[PolicyException:無法獲取所需的權限]

 [PolicyException: Required permissions cannot be acquired.] 
     System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +10238142 
     System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +97 

    [FileLoadException: Could not load file or assembly 'FileHelpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657' 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.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416 
     System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166 
     System.Reflection.Assembly.Load(String assemblyString) +35 
     System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190 

    [ConfigurationErrorsException: Could not load file or assembly 'FileHelpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)] 
     System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11207304 
     System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +388 
     System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +232 
     System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +48 
     System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +210 
     System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +76 
     System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +283 
     System.Web.Compilation.BuildManager.CompileGlobalAsax() +50 
     System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +676 

    [HttpException (0x80004005): Could not load file or assembly 'FileHelpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)] 
     System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +76 
     System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +1012 
     System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +1025 

[HttpException (0x80004005): Could not load file or assembly 'FileHelpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11301302 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4338644 

我試圖切換到FileHelpers 1.6不使用Reflection.Emit的,我得到這個異常:

Stack Trace: 


[PolicyException: Required permissions cannot be acquired.] 
    System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +10238142 
    System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +97 

[FileLoadException: Could not load file or assembly 'FileHelpers, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null' 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.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416 
    System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166 
    System.Reflection.Assembly.Load(String assemblyString) +35 
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190 

[ConfigurationErrorsException: Could not load file or assembly 'FileHelpers, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)] 
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11207304 
    System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +388 
    System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +232 
    System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +48 
    System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +210 
    System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +76 
    System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +283 
    System.Web.Compilation.BuildManager.CompileGlobalAsax() +50 
    System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +676 

[HttpException (0x80004005): Could not load file or assembly 'FileHelpers, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)] 
    System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +76 
    System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +1012 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +1025 

[HttpException (0x80004005): Could not load file or assembly 'FileHelpers, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11301302 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4338644 
+0

根據你提到的「full」的事實,你找到了找到解決方案的正確方向信任「,因爲錯誤肯定看起來像運行時無法授予FileHelpers必要的反射權限,這只是在部分信任配置下才會發生。這是否僅在通過VS進行調試時發生,還是在通過瀏覽器直接加載網站時發生(直接進入http:// localhost/myapp)? – 2009-12-09 16:05:00

+0

當我直接加載網站時,我沒有嘗試過這樣做,我會嘗試打電話給你,但是在VS中擺脫這個錯誤,我必須從WebUI/bin中刪除FileHelpers.dll,運行webapp ,關閉瀏覽器,停止webapp,重建(在bin中創建FileHelpers.dll)並再次運行它 – Omu 2009-12-10 07:31:33

+0

如果我在刪除dll後立即重建,它將不起作用 – Omu 2009-12-10 07:32:37

回答

3

排序在這裏黑暗中刺,但嘗試三件事情:

  • 在IIS管理器中,找到您的應用程序在其下運行的應用程序池,開闢高級設置。確保啓用32個applicaitons「設置爲true。

  • 請確保您正在運行Visual Studio爲管理員。

  • 檢查Solution Explorer中引用您的子項目。嘗試設置」副本本地「屬性的FileHelpers引用爲false,您可能需要直接在您的Web項目中添加對此程序集的引用,並且您將在此處將副本本地設置爲true(我已經看到過兩個子 - 試圖將相同引用的DLL推送到單個Web應用程序的項目可能會導致有趣的副作用)還要確保這兩個子項目都引用相同物理位置的EXACT相同FileHelpers程序集

+0

第一個提示加1。我有同樣的問題,它解決了這個問題。 – 2012-05-02 13:57:33

1

試試這個: 負載了.NET配置嚮導/工具(開始 - >控制面板 - >管理工具> .NET配置)

點擊運行安全策略

選擇「調整區域安全」在右側的面板上。

如果您正在加載不在本地硬盤驅動器上的DLL,那麼也會出現這個問題。如果這些文件在文件服務器等上,請將它移動到C:somewhere ..

0

我重新安裝了windows,IIS,VS之後問題消失了,所以我現在不是真的爲什麼會出現這個問題

+0

看這裏:http://meta.stackexchange.com/questions/37328/my-godits-full-of-unicorns,明天一切都會好的 – 2010-04-01 13:40:55

相關問題