Skip to content

The type initializer for 'System.Management.Automation.ExperimentalFeature' threw an exception. #18109

@ProRedMax

Description

@ProRedMax

Prerequisites

Steps to reproduce

I am experiencing a problem when running the PowerShell SDK in a kiosk (AssignedAccess) environment in a WindowsBackgroundService. When I am using the library in a non-kiosk environment it works fine. But the weird thing is that once I am in the kiosk or when I get back from it, I am always getting an exception. I already asked this on StackOverflow but without any solutions.

Expected behavior

$user = "ExamX"
$Sid = (Get-LocalUser -Name $user).SID.Value
Remove-LocalUser -SID $Sid
Clear-AssignedAccess
sc.exe stop "ExamX Service"
sc.exe delete "ExamX Service"
$path = "HKLM:\SOFTWARE\ExamX\ExamInfo\"
Remove-Item -Recurse $path -ErrorAction SilentlyContinue

Actual behavior

Exception Trace System.TypeInitializationException: The type initializer for 'System.Management.Automation.ExperimentalFeature' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'System.Management.Automation.Configuration.PowerShellConfig' threw an exception.
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String path1, String path2)
   at System.Management.Automation.Configuration.PowerShellConfig..ctor()
   at System.Management.Automation.Configuration.PowerShellConfig..cctor()
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExperimentalFeature..cctor()
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
   at System.Management.Automation.PowerShell.EndInvoke(IAsyncResult asyncResult)
   at ExamX_Service.WindowsService.PowershellHandler.Execute() in C:\ExamX\Service\ExamX_Service\ExamX_Service\PowershellHandler.cs:line 33
   at ExamX_Service.WindowsService.WindowsBackgroundService.RunRecoveryScript(ILogger`1 logger) in C:\ExamX\Service\ExamX_Service\ExamX_Service\WindowsBackgroundService.cs:line 134
   at ExamX_Service.WindowsService.WindowsBackgroundService.ExecuteAsync(CancellationToken stoppingToken) in C:\ExamX\Service\ExamX_Service\ExamX_Service\WindowsBackgroundService.cs:line 110

Error details

No response

Environment data

I can't really execute this command due to the exception being thrown

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-DevEx-SDKhosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions