This topic contains 2 replies, has 2 voices, and was last updated by
November 21, 2016 at 4:26 pm #58327ParticipantPoints: 0Rank: Member
I have a .NET DLL whose methods i want to call from DSC script resource. However the catch is that the .NET DLL expects STA threads only to call the methods. MTA threads will not work.
When i called the .NET method from DSC script resource, I am seeing that the method is not running because it is expecting STA whereas the Script is running in MTA.
Below is the bare bones Script resource
[string] $lgpoerr = $null
$lgpo = new-object LocalPolicy.LGPO_Executor
$success=$lgpo.ApplyLGPO($keypath,$valname,$data,$regtype,[ref][string]$lgpoerr) #this is the method call that expects to run in STA but instead is being run in MTA.
"Success" | Out-File -FilePath "D:\vamc\test-lgpo\out.txt"
$lgpoerr | Out-File -FilePath "D:\vamc\test-lgpo\out.txt"
Question:- How do i force DSC to run a certain script resource in STA apartment model instead of MTA apartment model?
November 21, 2016 at 5:22 pm #58337KeymasterPoints: 1,785Rank: Community Hero
I'm fairly certain you can't. Not without rewriting the LCM. Aside from the general bad-idea-ness of Script resources in terms of maintainability and modularity, the closest workaround I could think of would be to launch PowerShell.exe, since there's a switch that let's you specify.
November 21, 2016 at 8:38 pm #58361ParticipantPoints: 0Rank: Member
I found a simple way to solve this. See the below code
The topic ‘how to force DSC script resource to run under STA apartment’ is closed to new replies.