هذا التجميع لا يسمح للمتصلين الموثوق بهم جزئيا. initializeComponent ()

StackOverflow https://stackoverflow.com/questions/4314420

سؤال

سيناريو: أنا بصدد إعادة إنشاء أحد تطبيقاتنا لاستخدام nhibernate وصادف هذه المشكلة قبل أسبوعين. كانت القضية في الأصل مع nhibernate والقلعة وحل هذا تم إعادة تجميعهما مع [assembly: AllowPartiallyTrustedCallers]. ولكن بعد إجراء بعض التغييرات على واجهة المستخدم و CodeBase ، ظهر هذا الخطأ مرة أخرى. تجدر الإشارة أيضًا إلى أنني أتحكم في تحميل عناصر تحكم المستخدم برمجيًا من 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: 

أي شخص لديه أي أفكار حول هذا الموضوع؟ لقد أضفت بالفعل [Assembly: ALTERPARTILLETRUSTEDCALLERS] إلى التجميع. هل هناك أي طريقة لمعرفة أي مرجع (؟) يسبب هذا الخطأ؟ أو أي طريقة للتخطي من خلال initializeComponent ()؟

ملاحظة: لدي كل إذن مدرج ويتم تعيين المشروع على الثقة الجزئية.

على أي حال ، فإن أي مساعدة موضع تقدير كبير.

هل كانت مفيدة؟

المحلول

حسنًا ، إذا أردت استكشاف هذه المشكلة ، فسأقترب منها على النحو التالي:

1) إذا كنت أستخدم .NET 4.0 تأكد هذه تم التعامل معها بالفعل.

2) استخدم ildasm أو عاكس لفتح جميع DLLs المعنية على مجلد BIN للتأكد AllowPartiallyTrustedCallersAttribute تم تعيينهم عليها.

3) الاستخدام AppDomain.CurrentDomain.GetAssemblies() في وقت الخطأ (باستخدام نافذة فورية) لمعرفة أي التجميع يتم تحميله من أين. أعتقد أن هذا قد يكون مشكلتك كما رأيت في كثير من الأحيان أن الإصدارات القديمة أو المارقة من التجميع

أعتقد أن استخدام هذه الخطوات الثلاثة ستتمكن من العثور على مشكلتك.

نصائح أخرى

لجميع القراء في المستقبل من الذي قد فاته التعليقات تحت إجابة عليستاد.

في الأساس ما كان يعمل بالنسبة لي كان يأخذ عليستاد المشورة وإعادة تجميع جميع المراجع التي يمكنني معها leftPartilyTrustedCallersAttribute. للتحقق من التجميعات التي تم تحميلها تابعت الخطوة 2 من عليستاد النصيحة. بمجرد أن أتأكد الثقة الكاملة(وليس الثقة الجزئية).

ملحوظة: أنا أستخدم microsoft.office.interop.outlook لإرسال رسائل البريد الإلكتروني ويتطلب ثقة كاملة ولكن لا يزال يسمح للمواد الأخرى للتشغيل في ثقة جزئية.

آمل أن يساعد هذا مستخدمي المستقبل. أي أسئلة مجرد تعليق أدناه.

حصلت على هذا الخطأ عند تشغيل DLL من موقع الشبكة. كان DLL امتدادًا لـ ESRI Arcgis باستخدام ArcObjects التي تعمل في ArcGIS 10.1. الحل لا يفتح المشروع من موقع الشبكة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top