While building a basic Powershell cmdlet using this tutorial, I ran into an error when trying to install the cmdlet with InstallUtil:
An exception occurred during the Install phase.
System.InvalidOperationException: Unable to get installer types in the D:\SamplePowerShellProject\bin\Debug\MyCmdlets.dll assembly.
The inner exception System.Reflection.ReflectionTypeLoadException was thrown with the following error message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..
Why did I run into this error? When building my solution in Visual Studio, I noticed that
Add References didn’t have any references to the
System.Management.Automation namespace. The usual solution, c/o Stack Overflow, is to find the right DLL in
C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell.
In my case, I saw two subdirectories:
3.0. And to make it more confusing, my
$PSVersionTable showed a version of
The reason I saw this error is because I included the 3.0 version of the DLL instead of the 1.0 version. Once I switched the reference to the 1.0 version of the DLL, it installed without any issue.