Home
%3CLINGO-SUB%20id%3D%22lingo-sub-287870%22%20slang%3D%22en-US%22%3EPowershell%20ISE%20crashes%20on%20exit%20while%20using%20Microsoft.Web.Management.dll%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-287870%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Sep%2005%2C%202018%20%3C%2FSTRONG%3E%3CBR%20%2F%3EI%20was%20helping%20a%20customer%20other%20day%20on%20a%20stubborn%20crash%20whenever%20Powershell-ISE%20and%20Microsoft.Web.Management.dll%20are%20put%20together.%20While%20calling%20Microsoft.Web.Management.dll%20from%20Powershell-ISE%20or%20WMIprvse.exe%2C%20upon%20exit%2C%20it%20was%20throwing%20Runtime.InteropServices.InvalidComObject%20error%20while%20crashing%20the%20Powershell-ISE%20or%20WMIprvse.exe.%20Loading%2Fcalling%20the%20same%20DLL%20on%20the%20same%20machine%20from%20a%20C%23%20console%20application%20did%20NOT%20exhibit%20this%20behavior.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%3CSTRONG%3EError%20details%20from%20Event%20Log%3A%20%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E-%20%3CEVENT%20xmlns%3D%22%26quot%3B%22%3E%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fwin%2F2004%2F08%2Fevents%2Fevent%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fwin%2F2004%2F08%2Fevents%2Fevent%20%3C%2FA%3E%22%26gt%3B%20%3CBR%20%2F%3E-%20%3CSYSTEM%3E%20%3CBR%20%2F%3E%3CPROVIDER%20name%3D%22%26quot%3BWindows%22%20error%3D%22%22%20reporting%3D%22%22%3E%3C%2FPROVIDER%3E%20%3CBR%20%2F%3E%3CEVENTID%20qualifiers%3D%22%26quot%3B0%26quot%3B%22%3E1001%3C%2FEVENTID%3E%20%3CBR%20%2F%3E%3CLEVEL%3E4%3C%2FLEVEL%3E%20%3CBR%20%2F%3E%3CTASK%3E0%3C%2FTASK%3E%20%3CBR%20%2F%3E%3CKEYWORDS%3E0x80000000000000%3C%2FKEYWORDS%3E%20%3CBR%20%2F%3E%3CTIMECREATED%20systemtime%3D%22%26quot%3B2018-08-14T17%3A21%3A53.000000000Z%26quot%3B%22%3E%3C%2FTIMECREATED%3E%20%3CBR%20%2F%3E%3CEVENTRECORDID%3E6366%3C%2FEVENTRECORDID%3E%20%3CBR%20%2F%3E%3CCHANNEL%3EApplication%3C%2FCHANNEL%3E%20%3CBR%20%2F%3E%3CCOMPUTER%3EMYMACHINE%3C%2FCOMPUTER%3E%20%3CBR%20%2F%3E%3CSECURITY%3E%3C%2FSECURITY%3E%20%3CBR%20%2F%3E%3C%2FSYSTEM%3E%20%3CBR%20%2F%3E-%20%3CEVENTDATA%3E%20%3CBR%20%2F%3E%3CDATA%3E125883710853%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3E5%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3EPowerShell%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3ENot%20available%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3E0%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3EPowerShell_ISE.exe%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3E10.0.10586.117%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3ERuntime.InteropServices.InvalidComObject%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3ERuntime.InteropServices.InvalidComObject%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3Eunknown%3C%2FDATA%3E%20%3CBR%20%2F%3E%3CDATA%3ESystem.StubHelpers.StubHelpers.GetCOMIPFromRCW%3C%2FDATA%3E%20%3CBR%20%2F%3E%3C%2FEVENTDATA%3E%20%3CBR%20%2F%3E%3C%2FEVENT%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3ERepro%20steps%3A%20%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E-First%20verify%20that%20IIS%20Default%20Web%20Site%20is%20up%20and%20running%20without%20any%20issues%20(we%20will%20be%20referencing%20this%20site%20in%20the%20powershell%20script)%20%3CBR%20%2F%3E-Launch%20Powershell%20ISE%20in%20admin%20mode%20%3CBR%20%2F%3E-Run%20following%20commands%20one%20after%20another%20%3CBR%20%2F%3E%3CBR%20%2F%3E%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.Web.Management%22)%20%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(-Not%20(%5BMicrosoft.Web.Management.Server.ManagementAuthorization%5D%3A%3AGetAuthorizedUsers(%22Default%20Web%20Site%22%2C%20%24true%2C%200%2C%2010)%20%7C%20%3F%20Name%20-eq%20YourDomain%5CYourUserName))%20%7B%20%3CBR%20%2F%3E%24false%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%7B%20%3CBR%20%2F%3E%24true%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eexit%20%3CBR%20%2F%3E%3CBR%20%2F%3E-ISE%20crashes.%20%3CBR%20%2F%3E%20-Error%20logged%20in%20the%20Eventlog%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3EThe%20solution%3A%20%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3EReplace%20the%20exit%20with%20%3CBR%20%2F%3E%5BSystem.Environment%5D%3A%3AExit(0)%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-287870%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Sep%2005%2C%202018%20I%20was%20helping%20a%20customer%20other%20day%20on%20a%20stubborn%20crash%20whenever%20Powershell-ISE%20and%20Microsoft.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-287870%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Easp%20net%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIIS%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Emicrosoft%20web%20admin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Emicrosoft%20web%20management%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eruntime%20interopservices%20invalidcomobject%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ewmi%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on MSDN on Sep 05, 2018
I was helping a customer other day on a stubborn crash whenever Powershell-ISE and Microsoft.Web.Management.dll are put together. While calling Microsoft.Web.Management.dll from Powershell-ISE or WMIprvse.exe, upon exit, it was throwing Runtime.InteropServices.InvalidComObject error while crashing the Powershell-ISE or WMIprvse.exe. Loading/calling the same DLL on the same machine from a C# console application did NOT exhibit this behavior.

Error details from Event Log:
- <Event xmlns=" http://schemas.microsoft.com/win/2004/08/events/event ">
- <System>
<Provider Name="Windows Error Reporting" />
<EventID Qualifiers="0">1001</EventID>
<Level>4</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2018-08-14T17:21:53.000000000Z" />
<EventRecordID>6366</EventRecordID>
<Channel>Application</Channel>
<Computer>MYMACHINE</Computer>
<Security />
</System>
- <EventData>
<Data>125883710853</Data>
<Data>5</Data>
<Data>PowerShell</Data>
<Data>Not available</Data>
<Data>0</Data>
<Data>PowerShell_ISE.exe</Data>
<Data>10.0.10586.117</Data>
<Data>Runtime.InteropServices.InvalidComObject</Data>
<Data>Runtime.InteropServices.InvalidComObject</Data>
<Data>unknown</Data>
<Data>System.StubHelpers.StubHelpers.GetCOMIPFromRCW</Data>
</EventData>
</Event>

Repro steps:
-First verify that IIS Default Web Site is up and running without any issues (we will be referencing this site in the powershell script)
-Launch Powershell ISE in admin mode
-Run following commands one after another

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Management")

if (-Not ([Microsoft.Web.Management.Server.ManagementAuthorization]::GetAuthorizedUsers("Default Web Site", $true, 0, 10) | ? Name -eq YourDomain\YourUserName)) {
$false
}
else {
$true
}
exit

-ISE crashes.
-Error logged in the Eventlog

The solution:
Replace the exit with
[System.Environment]::Exit(0)