2013-02-11 49 views
1

我在初始化應用程序的階段遇到問題。安全異常 - mscorlib,使用CLSID檢索COM類組件失敗

public static void Initialise() 
    { 
     Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //throwing exception here 
     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); 
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 
    } 

我有web配置,其中

<trust level="full"/> 

消息是:

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 

堆棧跟蹤如下:

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) 
at System.Security.CodeAccessPermission.Demand() 
at System.Windows.Forms.Application.add_ThreadException(ThreadExceptionEventHandler value) 
at Chronos.Shared.ErrorHandler.Initialise() 
at Chronos.TeamLeader.Program.Main() 
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) 
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() 
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) 
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) 
at System.Activator.CreateInstance(ActivationContext activationContext) 
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() 
at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
at System.Threading.ThreadHelper.ThreadStart() 

讓我知道,如果有人需要更多信息關於它。

回答

3

我在通過這個安全例外掙扎了很多。閱讀大量博客,參與討論但沒有任何結果。

終於在msdn中找到'啓用ClickOnce安全設置'。我只是遵循這些步驟並禁用了項目屬性中的安全設置。

這裏是一個鏈接,希望這有助於一些:http://msdn.microsoft.com/en-us/library/1sfbfyk0.aspx

+0

當我從一個32位的開發機切換到64我有這個問題(不是100%肯定是相關的,但它是我在做什麼) 。該程序在Visual Studio之外運行,但在禁用ClickOnce安全性之前不會從Visual Studio中運行。非常感謝,這讓我瘋狂。 – jmoreno 2014-12-17 00:47:01

+0

只是想補充說,在我的情況下,它是一個WinForm應用程序,而不是一個Web應用程序。 – jmoreno 2014-12-17 00:53:46

+0

非常感謝!這讓我很渴望找到..在我的情況下,它也是winforms應用程序 – Jesse 2016-10-07 07:30:28

相關問題