سؤال

I'm using C# service to execute Powershell commands on a remote machine and show the results. I'm using C# library System.Management.Automation.Runspaces to executing the commands on remote system.

On one of the server, TypeInitializationException has occured while creating Runspace and the service is crashed.

WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("http://" + server + "/powershell"), strShellUri, cred);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
runspace = RunspaceFactory.CreateRunspace(connectionInfo);

Even after we capture the exception in try-catch block, the service is crashed. On googling, the exception is triggered by Inner Exception.

InnerException: System.EntryPointNotFoundException
Message=Unable to find an entry point named 'WSManInitialize' in DLL 'WsmSvc.dll'. StackTrace: at System.Management.Automation.Remoting.Client.WSManNativeApi.WSManInitialize(Int32 flags, IntPtr& wsManAPIHandle) at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager. WSManAPIStaticData..ctor() at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager ..cctor()

How can i resolve the inner exception issue.

هل كانت مفيدة؟

المحلول

The WsmSvc.dll (or one of its dependencies) is likely outdated (or an incompatible version)0 on your computer where you try to run your code. The only solution to this is to install / update this dll. (Assuming that the error message is correct.)

You can try using Dependency Walker to see if any dependent dll is missing or to inspect exported functions in WsmSvc.dll. Run it on the server where you get the error.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top