Add-Type -Path c:\AzureStorageFile\Microsoft.WindowsAzure.Storage.dll
$AzStorObject = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext
Gives me error
New-Object
: A constructor was not found. Cannot find an appropriate constructor for typeMicrosoft.WindowsAzure.Commands.Storage.AzureStorageContext
.
You are not passing the -ArgumentList
parameter to New-Object
, so when attempting to instantiate the specified type it will look for a constructor that takes no parameters. The parameterless constructor of the AzureStorageContext
class is protected
, not public
, though...
protected AzureStorageContext ();
...so New-Object
will not be able to invoke it.
That same Microsoft.WindowsAzure.Storage.dll
assembly is used by theAzure.Storage
package . Upon installing that...
Install-Module -Name Azure.Storage
...you can invoke the New-AzureStorageContext
cmdlet to create AzureStorageContext
instances...
$AzStorObject = New-AzureStorageContext # Additional parameters needed
Otherwise, there is a public
constructor of the AzureStorageContext
class...
public AzureStorageContext (Microsoft.WindowsAzure.Storage.CloudStorageAccount account);
...that you could use if you pass a CloudStorageAccount
instance...
$AzStorObject = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext -ArgumentList $myCloudStorageAccount
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.