Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在PowerShell v2中编译新类型-支持Cookie的WebClient_C#_Powershell_Webclient_Powershell 2.0 - Fatal编程技术网

C# 在PowerShell v2中编译新类型-支持Cookie的WebClient

C# 在PowerShell v2中编译新类型-支持Cookie的WebClient,c#,powershell,webclient,powershell-2.0,C#,Powershell,Webclient,Powershell 2.0,我正在尝试编译该类的“”版本,但似乎无法克服使用PowerShell v2中添加的Add-Type cmdlet的一些障碍。以下是我试图编译的代码: PS C:\> $def = @" public class CookieAwareWebClient : System.Net.WebClient { private System.Net.CookieContainer m_container = new System.Net.CookieContainer(); protecte

我正在尝试编译该类的“”版本,但似乎无法克服使用PowerShell v2中添加的Add-Type cmdlet的一些障碍。以下是我试图编译的代码:

PS C:\> $def = @"
public class CookieAwareWebClient : System.Net.WebClient
{
  private System.Net.CookieContainer m_container = new System.Net.CookieContainer();
  protected override System.Net.WebRequest GetWebRequest(System.Uri address)
  {
    System.Net.WebRequest request = base.GetWebRequest(address);
    if (request is System.Net.HttpWebRequest)
    {
      (request as System.Net.HttpWebRequest).CookieContainer = m_container;
    }
    return request;
  }
}
"@

PS C:\> Add-Type -TypeDefinition $def
它似乎找不到CookieContainer类型找不到(尽管它是完全限定的…)-显然我对某些东西是盲目的


编辑:将示例代码更新为正确且可复制粘贴,谢谢

使用构造函数表达式对
CookieContainer
的第二次引用是完全限定的。声明字段
m_container
时的第一个引用不是。使两者都完全合格,以便Powershell可以找到它们

private System.Net.CookieContainer m_container = new System.Net.CookieContainer();

谢谢我知道我是瞎子,但看不见!