设想: 我正在重构我们的一个应用程序,以使用NHIBERNATE,并在几周前遇到了这个问题。这个问题最初是在Nhibernate和Castle的 [assembly: AllowPartiallyTrustedCallers]. 。但是,在对UI和代码库进行了一些更改之后,此错误再次出现。还值得注意的是,我从form_main编程控制用户控件。

问题: 每当生成用户控件时,我都会收到以下错误。如果我评论加载,则该程序将运行。当我调试时,它以自动生成的initializecomponent()函数结束。请注意,我不能介入该功能。

System.Security.SecurityException was unhandled
      Message="That assembly does not allow partially trusted callers."
      Source="A"
      GrantedSet=""
      PermissionState=""
      RefusedSet=""
      Url="file:///C:/Documents and Settings/ID/Desktop/A-NHIB2/bin/Debug/A.EXE"
      StackTrace:
           at A.UserControlCyber.InitializeComponent()
           at A.UserControlCyber..ctor() in C:\Documents and Settings\ID\Desktop\A-NHIB2\UserControl_Cyber.cs:line 34
           at A.FormMain.FormMainLoad(Object sender, EventArgs e) in C:\Documents and Settings\ID\Desktop\A-NHIB2\Form_Main.cs:line 30
           at System.Windows.Forms.Form.OnLoad(EventArgs e)
           at System.Windows.Forms.Form.OnCreateControl()
           at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
           at System.Windows.Forms.Control.CreateControl()
           at System.Windows.Forms.Control.WmShowWindow(Message& m)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ContainerControl.WndProc(Message& m)
           at System.Windows.Forms.Form.WmShowWindow(Message& m)
           at System.Windows.Forms.Form.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
           at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Control.set_Visible(Boolean value)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(Form mainForm)
           at A.Program.Main() in C:\Documents and Settings\ID\Desktop\A-NHIB2\Program.cs:line 32
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.nExecuteAssembly(Assembly 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.runTryCode(Object userData)
           at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: 

有人对这个问题有任何想法吗?我已经在组装中添加了[汇编:允许的征收核心评估器]。有什么方法可以找出引起此错误的参考(?)?还是有什么方法可以逐步浏览initileizecomponent()?

笔记: 我有包括所有许可,并且该项目设置为部分信任。

无论如何,任何帮助都将受到极大的赞赏。

有帮助吗?

解决方案

好的,如果我要对此问题进行故障排除,我会如下处理:

1)如果我使用.NET 4.0确保 已经处理了。

2)使用Ildasm或Reflector打开BIN文件夹上的所有DLL,以确保 AllowPartiallyTrustedCallersAttribute 被放在他们身上。

3)使用 AppDomain.CurrentDomain.GetAssemblies() 在错误时(使用直接窗口),以查看从哪里加载哪个组件。我认为这可能是您的问题

我认为使用这三个步骤,您将能够找到您的问题。

其他提示

对于所有未来的读者 谁可能错过了阿里奥斯塔德(Aliostad)的回答下的评论。

基本上对我有用的是 Aliostad的 建议和重新编译我可以使用的所有参考 允许派对构成. 。要验证我遵循的加载的组件 第2步Aliostad的 建议。确保所有必需的dll具有该属性后,我将该属性包括到我的项目中,然后将我的项目设置为 完全信任(不是部分信任)。

笔记: 我使用Microsoft.office.interop.outlook来发送电子邮件,它需要完全信任,但仍然允许另一个DLL以部分信任运行。

希望这对未来的用户有所帮助。任何问题都在下面发表评论。

从网络位置运行DLL时,我遇到了这个错误。 DLL是使用ArcGIS 10.1中运行的ArcObjects的ESRI ArcGI的扩展。解决方案不要从网络位置打开项目。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top