Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to create an object of type Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule in Powershell. The Constructor takes a key and list of Rules. Below is the code. I get the following error. Error:

New-Object : Cannot find an overload for "SharedAccessAuthorizationRule" and the argument count: "2".
At line:39 char:10
     $Rule = New-Object -TypeName Microsoft.ServiceBus.Messaging.SharedAccessAuthori ...
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException
    FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Script:

cls    
Add-Type -Path "C:{Your Service Bus dll location}Microsoft.ServiceBus.dll"
Add-Type -Path "C:{Your WindowsAzure.configuration Location}Microsoft.WindowsAzure.Configuration.dll"
$AccessRights =  New-Object -TypeName 'System.Collections.Generic.List[Microsoft.ServiceBus.Messaging.AccessRights]' ;

$CanManage = $true;
$CanListen = $true;
$CanSend = $true;

if ($CanManage)
{
    $AccessRights  = $AccessRights + [Microsoft.ServiceBus.Messaging.AccessRights]::Manage;
}

if ($CanListen)
{
    $AccessRights  = $AccessRights + [Microsoft.ServiceBus.Messaging.AccessRights]::Listen;
}

if ($CanSend)
{
    $AccessRights  = $AccessRights + [Microsoft.ServiceBus.Messaging.AccessRights]::Send;
}

$Rule = New-Object -TypeName Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule -ArgumentList "2", $AccessRights;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
205 views
Welcome To Ask or Share your Answers For Others

1 Answer

    The array needs to be a strongly typed array. 

    Script that worked:
    cls    
    Add-Type -Path "C:{Your Service Bus dll location}Microsoft.ServiceBus.dll"
    Add-Type -Path "C:{Your WindowsAzure.configuration Location}Microsoft.WindowsAzure.Configuration.dll"

    #Strongly Typed Array
    [Microsoft.ServiceBus.Messaging.AccessRights[]]$AccessRights =  
    New-Object -TypeName "System.Collections.Generic.List[Microsoft.ServiceBus.Messaging.AccessRights]" ;

    $CanManage = $true;
    $CanListen = $true;
    $CanSend = $true;

        if ($CanManage)
        {
            $AccessRights  +=  [Microsoft.ServiceBus.Messaging.AccessRights]::Manage;
        }

        if ($CanListen)
        {
            $AccessRights  += [Microsoft.ServiceBus.Messaging.AccessRights]::Listen;
        }

        if ($CanSend)
        {

            $AccessRights  += [Microsoft.ServiceBus.Messaging.AccessRights]::Send;
        }    

    $AccessRights;    

        $Rule = New-Object -TypeName Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule -ArgumentList "2", $AccessRights;

        $Rule;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...