1

I would appreciate some clarification. When using a .NET Framework Class in PowerShell we sometimes have to load the Assembly into memory we have to use the Add-Type Cmdlet in PowerShell. So for instance if I wanted to use the System.ServiceProccess.ServiceController Class I would do something like this

Add-Type -AssemblyName System.ServiceProcess

But here is where I get confused. The documentation says there are 2 assemblies for the System.ServiceProcess.ServiceController Class

https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicecontroller?view=netframework-4.8 namely: System.ServiceProcess.ServiceController.dll, and System.ServiceProcess.dll

It seems to work no matter which one I add but I would like to know what is happening under the hood of the bonnet.

Even more confusing is the Process class : https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=netframework-4.8

Here we have 3 assemblies : System.Diagnostics.Process.dll, System.dll and netstandard.dll

I can only load System.Dll. The other 2 it simply says the assembly can't be found.

So the question is, if I want to use and .NET Framework Class I Assume I should have all the aasemblies so how do I load them all in PowerShell?

Hope this is clear and thanks for an answer.

Kind regards,

John

2 Answers 2

0

System.ServiceProcess.dll is in the GAC, and part of the .NET Framework. System.ServiceProcess.ServiceController.dll is part of the Core CLR.

But wait a minute - PowerShell is based on the .NET Framework CLR.

If you build your assembly against the correct netstandard profile, and its dependencies are resolvable, it should be able to run on the .NET Framework.

You can see that System.ServiceProcess.dll references kernel32, while System.ServiceProcess.ServiceController.dll references api-ms-win-service-core.

It's sort of the same, but the Core CLR version will have presumably less functionality.

As for the others, most of the System namespace resides in mscorlib and System.dll. In recent years, there has been an effort to make the core library leaner by moving parts of it out, to have out-of-band delivery.

For example, System.Diagnostics.Process.dll now ships as a nuget package, which enables faster rollouts to users rather than shipping a major .NET Framework update that targets are required to install.

If you're using regular Powershell and not Powershell Core, you can just reference .NET Framework assemblies and not see confusing

0

MSDN fails to properly indicate which type belongs to which assembly either in .NET Framework, .NET Core or .NET Standard.

You can use .NET API Catalog instead:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.