c# - Powershell Azure CmdletInvocationException -


i have problem using powershell azure. have small c# console application running powershell azure commands.

this code:

public class powershellservice : idisposable {     private powershell _shellinstance;     private psdatacollection<psobject> _outputcollection;     private runspace rs;      public event eventhandler<dataeventargs> data;     public event eventhandler<errorrecordeventargs> error;      public powershellservice()     {         initializeshellinstance();     }      private void initializeshellinstance()     {         initialsessionstate iss = initialsessionstate.createdefault();         string[] modules = new string[] { "full path azure.psd1", "full path azurerm.psd1" };         iss.importpsmodule(modules);          _shellinstance = powershell.create();         string initializationscript = "set-executionpolicy -scope process -executionpolicy remotesigned";         _shellinstance.addscript(initializationscript);         _shellinstance.invoke();          rs = runspacefactory.createrunspace(iss);         rs.open();         ...         ...         ... 

exception occurs on line: rs.open()

the exception follows:

an unhandled exception of type 'system.management.automation.cmdletinvocationexception' occurred in system.management.automation.dll  additional information: exception calling ".ctor" "0" argument(s): "the type initializer 'microsoft.azure.commands.resourcemanager.common.azurermcmdlet' threw exception." 

solution: reinstalled related azure , worked


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -