1

管理された dll – repro.dll があります。これには、System.ObsoleteAttribute と System.Management.Automation.CmdletAttribute (Windows 7 の GAC にある System.Management.Automation.dll から取得) の 2 つの属性で装飾されたクラス TestModuleCommand が含まれています。

        namespace Test {
            [System.Obsolete]
            [System.Management.Automation.Cmdlet("Test", "Module")]
            public class TestModuleCommand : System.Management.Automation.PSCmdlet {
                protected override void ProcessRecord() {
                    this.WriteObject("In test-module");
                }
            }
        }

repro.dll がローカル ディレクトリに配置されている場合、System.Type.GetCustomAttributes(false) から返された両方の属性を確認できます。repro.dll がネットワーク パスに配置されている場合、1 つの属性しか表示されません (ただし、System.Reflection.CustomAttributeData.GetCustomAttributes(MemberInfo) を介して両方の属性が表示されます)。これは望ましくありません。両方の属性を確認したいのです (CmdletAttribute をインスタンス化してもセキュリティに影響がないことはわかっています)。

私がオンラインで見つけたものから、repro.dll (ネットワークの場所からロードされた場合) が SMAdll を完全に認識できないことを漠然と認識しています。CAS を使用すると System.Management.Automation で CmdletAttribute が安全であることを宣言できると思いますが、その宣言の書き方がわかりません。何が起こっているのかを完全に理解するには、どこで詳細を読むことができますか? どんな知恵の言葉も歓迎します。

ありがとう、

ルカシュ

PS。以下は、誰でも powershell.exe プロンプトで試すことができる再現です (Windows 7 の場合 - Add-Type コマンドレットは PowerShell v2 の新機能です)。

PS C:\> Add-Type -TypeDefinition @"
>>             namespace Test {
>>                 [System.Obsolete]
>>                 [System.Management.Automation.Cmdlet("Test", "Module")]
>>                 public class TestModuleCommand : System.Management.Automation.PSCmdlet {
>>                     protected override void ProcessRecord() {
>>                         this.WriteObject("In test-module");
>>                     }
>>                 }
>>             }
>> "@ -OutputAssembly \\axp-test\scratch\lukasza\repro.dll -OutputType Library
>>
PS C:\> # local copy would work...
PS C:\> # Copy \\axp-test\scratch\lukasza\repro.dll ~\repro.dll
PS C:\>
PS C:\> $a = [System.Reflection.Assembly]::LoadFrom("\\axp-test\scratch\lukasza\repro.dll")
PS C:\> $t = $a.GetType("Test.TestModuleCommand")
PS C:\> $t.GetCustomAttributes($false) # only 1 attribute is visible here

Message                                   IsError TypeId
-------                                   ------- ------
                                          False     System.ObsoleteAttribute


PS C:\>
PS C:\> [System.Reflection.CustomAttributeData]::GetCustomAttributes($t) # but I can see both attributes here

Constructor                             ConstructorArguments  NamedArguments
-----------                             --------------------  --------------
Void .ctor(System.String, System.Str... {"Test", "Module"}    {}
Void .ctor()                            {}                    {}


PS C:\>
PS C:\> $a.Evidence

                                           SecurityZone
                                           ------------
                                           Intranet
4

1 に答える 1

2

これが私が見つけた答えです: Haibo Luo - My Attribute Disappears

于 2010-01-08T00:19:44.653 に答える