HTMLページ(IE7)に埋め込まれた.Net 2.0のactivexコントロールがあります。javascript を使用してプロパティを変更し、メソッドを呼び出します。Activator.CreateInstance(type) を使用してクラスをインスタンス化するメソッドを呼び出すまでは、これで問題ありません。次のメッセージが表示されます。
System.Reflection.TargetInvocationException: 呼び出しのターゲットによって例外がスローされました。---> System.Security.SecurityException: 要求が失敗しました。
..
..
失敗したアクション: InheritanceDemand
最初に失敗したアクセス許可の種類: System.Security.PermissionSet 失敗
したアセンブリのゾーン: イントラネット
私がインスタンス化しようとしているクラスには、parm-lessパブリックコンストラクターがあり、私が読んだことから、パブリックな型でリフレクションを使用しても問題はないはずです。
Microsoft .NET Framework 構成ユーティリティを使用して一時的な修正を行い、イントラネットの信頼を完全に変更しました。ここを参照してください。
フレームワークを構成する必要がないように、メソッド、クラス、またはアセンブリを変更するにはどうすればよいですか?
いくつかの追加ポイント:
- ActiveX コントロールは .Net 2 に対してコンパイルされます
- そのアセンブリは厳密な名前ではありません
- リフレクションの許可を与えることは気にしません。
ありがとう
アップデート
問題の原因はリフレクションではなく、FileIOPermission セキュリティ例外をスローした TypeDescriptor.GetAttributes の呼び出しであることが判明しました。次のコードでこれを修正しました。
Dim temp As New Security.Permissions.FileIOPermission(Security.Permissions.PermissionState.Unrestricted)
temp.Assert()
// Get attributes
System.Security.CodeAccessPermission.RevertAssert()
ここで、アセンブリの厳密な名前に割り当てられたコード グループをセットアップし、アクセス許可セットをFullTrustに設定すると、すべて問題ありません。
ただし、微調整できないようです。FullTrustであるか、例外がスローされます (以下を参照)。すべてのアクセス許可セットでさえ機能しません。
例外:
System.Security.SecurityException: Request failed.
at System.Reflection.CustomAttribute._CreateCaObject(Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(Module module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetAttributes(Type type)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetAttributes()
at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()
at System.ComponentModel.TypeDescriptor.GetAttributes(Object component, Boolean noCustomTypeDesc)
at System.ComponentModel.TypeDescriptor.GetAttributes(Object component)
... GetAttributes
...
The action that failed was: InheritanceDemand
The type of the first permission that failed was: System.Security.PermissionSet
The Zone of the assembly that failed was: Intranet