Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Set Runspaces to use STA when running in Windows PowerShell #769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set Runspaces to use STA when running in Windows PowerShell #769
Changes from all commits
22791c6
454bd6d
46afe90
55427d4
2ed6294
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in PowerShellStandard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no such property in PSCore, and PSStandard is PSCore ∩ Windows PowerShell. So it makes sense it's not in PSStandard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could possibly be in PSStandard but then throw Not Implemented Exception for PSCore.
We shouldn't need to use reflection.
This is an edge case for sure but we should talk about it.
Cc @SteveL-MSFT @JamesWTruher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tylerl0706 If the member has been removed completely, wouldn't that throw a missing member exception at runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PSCore6 currently doesn't support setting apartmentstate. There's currently no plan to add it back. One of the things I dislike about .NET Std is APIs that exist but throw PlatformNotSupportedException at runtime meaning I can't rely on build time to find api problems for cross platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense and I'm definitely not asking for it. More concerned about:
I can understand your dislike for that but the alternative is to use reflection which isn't really elegant, right?
I don't know the .NET Std team's reasoning behind going down that route but I wouldn't be surprised if this was part of that reasoning:
"not having to rely on reflection for scenarios when you have to do extra work on one platform to get the expected behavior on all"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, it's the lesser of two evils. I don't think reflection in itself is necessary a bad thing as long as you use a publicly documented API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally in favour of compile time checking helping to identify what would otherwise be an unforeseeable runtime crash. But either way, the reflection done here is (1) done once, (2) efficiently compiled to a delegate and (3) called as readably as I could make it -- so hopefully that smooths over the clumsiness of reflection a little bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's totally fine. Just wanted to bring it up. If we want to go down this route we should at least have a doc on best practices for these sorts of things.