2010-01-06 1 views
1

У меня есть управляемая dll - repro.dll, которая содержит класс TestModuleCommand, украшенный 2 атрибутами: System.ObsoleteAttribute и System.Management.Automation. CmdletAttribute (происходит от System.Management.Automation.dll, который находится в GAC в Windows 7)System.Type.GetCustomAttributes на сборке, загруженной из общего сетевого ресурса, не отображает все атрибуты

 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 (ложный). Если файл rep.dll помещается в сетевой путь, то я вижу только один атрибут (хотя я все еще вижу оба атрибута через System.Reflection.CustomAttributeData.GetCustomAttributes (MemberInfo)). Это нежелательно - я хочу видеть оба атрибута (я знаю, что экземпляр CmdletAttribute не влияет на безопасность).

Из того, что я нашел в Интернете, я смутно знаю, что файл rep.dll (если он загружен из сетевого местоположения) не может полностью увидеть файл S.M.A.dll. Я думаю, что 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 

ответ