[英]Attempt by security transparent method to access security critical method failed
[英]System.MethodAccessException: Attempt by security transparent method to access security critical method fails on all applications
您好,並提前感謝您的幫助,我知道這個問題或類似的問題已經發布,經常對MVC 3應用程序有特殊的關注。 但是,每當我嘗試使用.net 4.0目標框架從visual web developer express 2010中啟動任何應用程序時,我都會收到此錯誤消息。
確切的錯誤消息是:
嘗試使用安全透明方法'System.Runtime.Diagnostics.DiagnosticTrace..ctor(System.String,System.Guid)'來訪問安全關鍵方法'System.Runtime.Diagnostics.EtwDiagnosticTrace..ctor(System.String,System.Guid) )'失敗'。
程序集“System.ServiceModel.Internals,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”標有AllowPartiallyTrustedCallersAttribute,並使用2級安全透明度模型。 2級透明度導致AllowPartiallyTrustedCallers程序集中的所有方法默認情況下變為透明安全性,這可能是此異常的原因。
堆棧跟蹤:
[MethodAccessException: Attempt by security transparent method 'System.Runtime.Diagnostics.DiagnosticTrace..ctor(System.String, System.Guid)' to access security critical method 'System.Runtime.Diagnostics.EtwDiagnosticTrace..ctor(System.String, System.Guid)' failed.
Assembly 'System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.]
System.Runtime.Diagnostics.DiagnosticTrace..ctor(String traceSourceName, Guid etwProviderId) +24
System.ServiceModel.Activation.FxTrace.InitializeTracing() +90
System.ServiceModel.Activation.FxTrace.get_Trace() +84
System.ServiceModel.ServiceHostingEnvironment.EnsureInitialized() +59
System.ServiceModel.ServiceHostingEnvironment.OnEnsureInitialized(Object state) +4
System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state) +52
System.ServiceModel.ServiceHostingEnvironment.SafeEnsureInitialized() +65
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +58
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +143
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
我在這里完全不知所措。 如果我從頭開始創建任何基本應用程序並嘗試啟動它,即使沒有添加任何內容,我也會收到此錯誤屏幕。 我試過從中刪除target framework =“4.0”屬性
<compilation debug="true" targetFramework="4.0" />
標記並運行它沒有任何結果。 我試過刪除該屬性並添加
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0.30319"/>
</startup>
正如此線程中所建議的: BadImageFormatException - 是否可以指定用於運行可執行文件的.NET版本? 我嘗試修復.Net 4.0框架安裝,因為我聽說這可能是一個問題。 我剛剛安裝了可視化Web開發人員,以便處理我從Microsoft Visual Studio 2010移動的項目,因為我的試用版已過期,任何幫助或潛在的解決方法都將受到贊賞。
我今天遇到過這個問題。 據我所知,問題是.NET 4.0程序集現在默認為安全關鍵 。 安全透明代碼無法調用安全關鍵代碼。
我的解決方案涉及只在我的應用程序中的幾個程序集上定義AllowPartiallyTrustedCallersAttribute
。 我必須從所有程序集中刪除此屬性,或將其添加到所有程序集中。
您可能需要將以下內容添加到AssemblyInfo.cs文件中,以使所涉及的程序集相同。
[assembly: SecurityTransparent()]
感謝我在這里參加聚會非常晚,但是在VS2013中遇到了與.NET 4.5.1 ClickOnce項目同樣的問題,我通過以下方式解決了這個問題:
希望這有助於其他人!
顯然,一個潛在的解決方法至少使我能夠在Visual Web Developer中啟動應用程序是這樣的:
從位於元素中的元素中刪除targetFramework =“4.0”屬性。
如果是Silverlight應用程序,請右鍵單擊ApplicationName.Web標頭選擇屬性,然后將目標框架更改為3.5。 如果是asp.net應用程序,請右鍵單擊頂部項目標題並選擇屬性,然后將目標框架設置為3.5。
所有這些都告訴我,我的.Net 4.0框架安裝存在問題。 但是因為我已經安裝和卸載然后至少安裝了兩次.Net 4.0框架,所以這是我能想到的唯一選擇。 如果有人給我一個更好的回應/更永久的解決方案,對我有用,我會將其標記為答案。 與此同時,我將嘗試啟動“安裝其他框架”並再次重新安裝.Net 4.0目標包和.Net 4.0 Runtime以查看它是否有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.