そのアセンブリは、部分的に信頼できる発信者を許可しません。 initializeComponent()

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

質問

シナリオ: 私は、Nhibernateを使用するためのアプリケーションの1つをリファクタリングする過程にあり、数週間前にこの問題に出会いました。この問題はもともと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: 

誰かがこのテーマに関するアイデアを持っていますか?私はすでに[アセンブリ:Plartivally -strustedCallers]をアセンブリに追加しました。どの参照(?)がこのエラーを引き起こしているかを見つける方法はありますか?または、initializeComponent()をステップスルーする方法はありますか?

ノート: 私はすべての許可を含めており、プロジェクトは部分的な信頼に設定されています。

とにかく、どんな助けも大歓迎です。

役に立ちましたか?

解決

わかりました、もし私がこの問題をトラブルシューティングするなら、私は以下のようにそれにアプローチします:

1).NET 4.0を使用している場合は確認してください これ すでに処理されています。

2)IldasmまたはReflectorを使用して、Binフォルダーで問題のすべてのDLLを開き、確認する AllowPartiallyTrustedCallersAttribute それらに設定されています。

3)使用します AppDomain.CurrentDomain.GetAssemblies() エラーの時点で(即時ウィンドウを使用)、どこからどのアセンブリがロードされているかを確認します。これは、古いバージョンや不正なアセンブリがGACまたはさまざまなビンフォルダーからロードされていることをよく見たので、あなたの問題になると思います。

これらの3つのステップを使用すると、問題を見つけることができると思います。

他のヒント

すべての将来の読者のために アリオスタドの答えの下でコメントを見逃した人かもしれません。

基本的に私のために働いていたのは取っていました アリオスタッドの 私ができるすべての参照をアドバイスして再コンパイルします Allowpartially -strustedCallerSattribute. 。ロードしたアセンブリを確認するには、私が従いました ステップ2アリオスタッドの 助言。必要なすべてのdllがその属性を持っていることを確認したら、私はその属性を私のプロジェクトに含め、プロジェクトをに設定しました 完全な信頼(部分的な信頼ではありません)。

ノート: Microsoft.office.interop.outlookを使用して電子メールを送信していますが、完全な信頼が必要ですが、他のDLLが部分的な信頼で実行できるようにしています。

これが将来のユーザーに役立つことを願っています。質問は以下のコメントだけです。

ネットワークの場所からDLLを実行すると、このエラーが発生しました。 DLLは、ArcGIS 10.1で実行されているArcobjectsを使用したEsri Arcgisの拡張機能でした。ソリューションネットワークの場所からプロジェクトを開かないでください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top