Share via

Call Connect-Azccount using c#

Anil Kumar 6 Reputation points
2021-06-14T16:36:23.9+00:00

Hello

Using System.Management.Automation.Runspaces
Calling azure powershell module using c# application , connect-azaccount throws this exception.

System.Management.Automation.CmdletInvocationException: Method 'SendRequest' in type 'Microsoft.Azure.ServiceManagement.Common.Models.RecordingTracingInterceptor'
from assembly 'Microsoft.Azure.PowerShell.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation. --->
System.TypeLoadException: Method 'SendRequest' in type 'Microsoft.Azure.ServiceManagement.Common.Models.RecordingTracingInterceptor' from assembly
'Microsoft.Azure.PowerShell.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.SetupDebuggingTraces()
at Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet.SetupDebuggingTraces()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.BeginProcessing()
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.BeginProcessing()
at System.Management.Automation.Cmdlet.DoBeginProcessing()
at System.Management.Automation.CommandProcessorBase.DoBegin()
--- End of inner exception stack trace ---
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)

Azure Automation
Azure Automation

An Azure service that is used to automate, configure, and install updates across hybrid environments.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anil Kumar 6 Reputation points
    2021-06-17T05:29:42.26+00:00

    I was able to run changing ,net target framework to 4.8. it was 4.6 before.

    Thank you

    Was this answer helpful?


  2. Monalla-MSFT 13,166 Reputation points Moderator
    2021-06-16T15:14:07.407+00:00

    Hello @Sai Pranav - Thanks for reaching out.

    It appears you are calling it from C#.

    Connect-AzAccount

    is a PowerShell cmdlet (not an executable) and has to be run from within a PowerShell session, either interactively or from within a PowerShell script or by upgrading your version.

    Hope that helps.

    Please feel free to "Accept as Answer" if it helped answer your query.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.