Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint

Issue

 
Recently, we were developing a custom webpart for SharePoint 2019 On-Premise. We got the below error while deploying the solution,
 
Error occurred in deployment step 'Recycle IIS Application Pool': Invalid namespace
 
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
 

Analysis

 
We have faced this issue in the past . We thought it was an  issue in the  .Net framework of the project. We tried to reduce the .Net framework to 4.5. But that didn't solve the issue this time. Then we Googled the issue and found out there were some configuration changes we need to do in the development environment.
 

Solution

 
We found out that we need to add a  "IIS 6 WMI Compatibility" feature. Please follow the below steps to add the same,
  • If you are using Windows server, go to server manager.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • Click on “Add Roles and Feature”
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • It will open “add feature” dialog. Click next until you reach “Server Roles”.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
 
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
 
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint 
  • In that, expand “Web Server (IIS)”
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • In that expand “Management Tools”
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • In that expand “IIS 6 Management Compatibility”
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • In that, check “IIS 6 WMI Compatibility”, “IIS 6 Metabase Compatibility” & “IIS 6 Management Console” and click Next.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
 
Note
In my case the first two were installed. If it is not installed in your side, it will show as not checked.
  • Click Next in feature selection.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • Click Install in confirmation installation screen.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • It will start installing the feature. Wait for the completion.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • Click close once done.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • Restart visual studio and try to deploy the project and it will deploy successfully.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
 
If you are using a Windows operating system machine, then you can follow the below steps to install “IIS 6 WMI Compatibility”:
  • Go to Control panel.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • Click on Program.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • Click on “Turn Windows Feature on or Off” (you will require admin rights for this).
  • It will open feature dialog.
  • Open Internet Information Services.
  • Open Web Management Tools.
  • Open IIS 6.0 Management Compatibility.
  • Click to select the IIS 6 Metabase and IIS 6 configuration compatibility, IIS 6 WMI Compatibility, and IIS 6 Management Console check boxes.
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint
  • Click OK.
You can set this up using powershell as well.
 
Follow the below steps for the same,
  • Open “Windows PowerShell” in administrator mode.
  • You need to first import server manager module.
  • Then you can run command to run feature.
PS C:\windows\system32>Import-Module servermanager
PS C:\windows\system32> Add-WindowsFeature Web-WMI
 
The output will look like below,
 
Error Occurred In Deployment Step 'Recycle IIS Application Pool' - Invalid Namespace SharePoint