Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.ContainerBase constructor not found #23462

Closed src107 closed 9 months ago

src107 commented 1 year ago

Description

A constructor was not found. Cannot find an appropriate construc tor for type Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.ContainerBase." was thrown

Script or Debug output

$test = New-Object Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.ContainerBase

Environment data

No response

Module versions

PS version - 5.1.19041.3693 Az.RecoveryServices version - 6.6.1

Error output

$test = New-Object Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.ContainerBase
New-Object : A constructor was not found. Cannot find an appropriate constructor for type 
Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.ContainerBase.
At line:1 char:9
+ $text = New-Object Microsoft.Azure.Commands.RecoveryServices.Backup.C ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands..NewObjectCommand
microsoft-github-policy-service[bot] commented 12 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @pvrk, @adityabalaji-msft.

isra-fel commented 12 months ago

Thanks for the feedback. I'll route this to Recovery Services team. BTW could you provide the version of PowerShell and the Az.RecoveryServices module you were using?

microsoft-github-policy-service[bot] commented 12 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @pvrk, @adityabalaji-msft.

src107 commented 12 months ago

Thanks for the feedback. I'll route this to Recovery Services team. BTW could you provide the version of PowerShell and the Az.RecoveryServices module you were using?

Hi, I have added the module and powershell version in the Module Versions section

adityabalaji-msft commented 11 months ago

Adding @Daya-Patil to review

Daya-Patil commented 11 months ago

I am wondering on the need to initialize these classes directly, we recommend to use Get-AzRecoveryServicesBackupContainer command. It is fairly very complicated to achieve this. However if it is a hard requirement, the right way to do this is

$protectionContainerResource = [Microsoft.Azure.Management.RecoveryServices.Backup.Models.ProtectionContainerResource]::new() $protectionContainerResource.Properties = [Microsoft.Azure.Management.RecoveryServices.Backup.Models.ProtectionContainer]::new()

initialize the values to the variable $protectionContainerResource and $protectionContainerResource.Properties for each field/property needed inside the object, then initialize the ContainerBase

or AzureVmContainer/AzureStorageContainer/ AzureVMAppContainerProtectionContainer class.

$containerBase = [Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.ContainerBase]::new($protectionContainerResource)

here are some code references -

1) AzureVmContainer - azure-powershell/src/RecoveryServices/RecoveryServices.Backup.Models/AzureVmModels/AzureVmContainer.cs at main · Azure/azure-powershell (github.com)

2) AzureContainer - azure-powershell/src/RecoveryServices/RecoveryServices.Backup.Models/AzureModels/AzureContainer.cs at main · Azure/azure-powershell (github.com)

3) ContainerBase - azure-powershell/src/RecoveryServices/RecoveryServices.Backup.Models/BaseObjects.cs at main · Azure/azure-powershell (github.com)

4) we first fetch the ProtectionContainerResource from .NET SDK (via service API call) and then initialize these object that customer is trying to initialize directly - azure-powershell/src/RecoveryServices/RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs at main · Azure/azure-powershell (github.com)

Daya-Patil commented 9 months ago

closing as have not received reply