2013-02-11 70 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

相关问题