22

アンマネージコードとの混合アセンブリであるSystem.Data.SQLite.DLLの使用例を示し ます。これを実行すると:

  var assembly= Assembly.LoadFrom("System.Data.SQLite.DLL")

例外はスローされませんが、これを行うと:

  var rawAssembly = File.ReadAllBytes("System.Data.SQLite.DLL");
  var assembly = Assembly.Load(rawAssembly);

CLRは、「検証不可能なコードがポリシーチェックに失敗しました。(HRESULTからの例外:0x80131402)」というFileLoadExceptionをスローします。このアセンブリを子AppDomainにロードしようとしているとしましょう。ポリシーチェックに合格できるように、AppDomainのセキュリティをカスタマイズするにはどうすればよいですか。

4

2 に答える 2

20

We are the victim of a crummy exception message. Loading assemblies with Assembly.Load(byte[]) that contain unmanaged code is not supported. This is the subject of this feedback item.

UPDATE: the linked feedback item is gone, deleted as part of the cleanup at VS2012 release time. The only part of it could still recover is this fragment, copied from another web page:

“[…] we only allow ILOnly images to be loaded […] since anything else is not safe”--

UPDATE: link fixed with archive.org backup copy.

于 2010-05-31T17:43:49.063 に答える
12

問題は、CLRが通常のDLLロード手順を実行しないことです。たとえば、dllの個別のセクションを別のページにマッピングしたり、修正プログラムを調整したりします。アセンブリがrawバイトからロードされると、それらのrawバイトはそのままメモリにマッピングされます。管理されたメタデータのみが読み取られます。証拠やセキュリティ設定の量がこの動作を変更することはありません。

于 2011-05-27T00:58:00.087 に答える