-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Enable ApartmentState support #4772
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
Conversation
19b0dbc to
4d1e4f8
Compare
4d1e4f8 to
9a7782d
Compare
| // So just return the CurrentTimeZone. | ||
|
|
||
| #if !CORECLR // TimeZone Not In CoreCLR | ||
| #if !CORECLR // TimeZone deprecated, need to change to TimeZoneInfo |
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.
Maybe add that this change affects serialization, remoting and backward compatibility. We can go back to that when we'll have tests for the areas.
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.
Good suggestion, will add
| // So just return the CurrentTimeZone. | ||
|
|
||
| #if !CORECLR // TimeZone Not In CoreCLR | ||
| #if !CORECLR // TODO: TimeZone deprecated, need to change to TimeZoneInfo. Affects serialization, remoting, and backwards compatibility. |
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.
According to documentation here: https://docs.microsoft.com/en-us/dotnet/api/system.timezone?view=netcore-2.0
TimeZone class can still be used to get CurrentTimeZone. A comment about deprecation might not be accurate.
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.
At compilation time, dotnet reported it as deprecated
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 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.
@SteveL-MSFT
What do you mean when you say the WSManConfigProvider doesn't work? Do you have repro steps and errors?
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.
@PaulHigin using sta, you would get this error:
dir : COM object that has been separated from its underlying RCW cannot be used.
At line:1 char:1
+ dir
+ ~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], InvalidComObjectException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.InvalidComObjectException,Microsoft.PowerShell.Commands.GetChildItemCommand
| #if !CORECLR | ||
| runspace.ApartmentState = ApartmentState.STA; | ||
| #endif | ||
| runspace.ThreadOptions = PSThreadOptions.ReuseThread; |
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.
Is this line supposed to be removed?
| if (Credential_Delegation_Key == null) | ||
| Credential_Delegation_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation | ||
| #if !CORECLR | ||
| , RegistryKeyPermissionCheck.ReadWriteSubTree |
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.
Microsoft.Win32.RegistryKeyPermissionCheck is available in .NET Core. Maybe we should keep it?
| if (Allow_Fresh_Credential_Key == null) | ||
| Allow_Fresh_Credential_Key = rootKey.CreateSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials | ||
| #if !CORECLR | ||
| , RegistryKeyPermissionCheck.ReadWriteSubTree |
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.
Same here.
| if (Environment.OSVersion.Version.Major < 6) | ||
| { | ||
| //OS is XP/Win2k3. Throw error. | ||
| string message = helper.FormatResourceMsgFromResourcetext("CmdletNotAvailable"); |
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.
Maybe the resource string CmdletNotAvailable can be removed?
| <ItemGroup> | ||
| <ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" /> | ||
| <ProjectReference Include="..\Microsoft.WSMan.Runtime\Microsoft.WSMan.Runtime.csproj" /> | ||
| <PackageReference Include="System.ServiceProcess.ServiceController" Version="4.4.0" /> |
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.
Did you rebase? Some changes in this PR is also in #4756
| RegistryKey rGPOLocalMachineKey = Registry.LocalMachine.OpenSubKey( | ||
| Registry_Path_Credentials_Delegation + @"\CredentialsDelegation", | ||
| #if !CORECLR | ||
| RegistryKeyPermissionCheck.ReadWriteSubTree, |
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.
Same here.
| { | ||
| rGPOLocalMachineKey = rGPOLocalMachineKey.OpenSubKey(Key_Allow_Fresh_Credentials, | ||
| #if !CORECLR | ||
| RegistryKeyPermissionCheck.ReadWriteSubTree, |
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.
ditto
| #if CORECLR | ||
| "0409" /* TODO: don't assume it is always English on CSS? */ | ||
| #else | ||
| String.Concat("0", String.Format(CultureInfo.CurrentCulture, "{0:x2}", checked((uint)CultureInfo.CurrentUICulture.LCID))) |
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.
Shall we use the #else block instead?
| else if (i > 100) | ||
| i = 100; // maximum 100MB | ||
| return i * 1000000; | ||
| // TODO: move this to startupconfig is needed. This number is in bytes. |
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.
Can you add one more comment indicating we use 10MB by default?
| _closed = false; | ||
| } | ||
| #else | ||
| internal PipelineThread(ApartmentState apartmentState) |
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.
Is it possible that this method can be called on Unix plats? If so, _worker.SetApartmentState(apartmentState) might throw.
|
@daxian-dbw I've been thinking that I've been looking at this problem the wrong way. ApartmentState is only used for COM interop and dotnet will marshal between STA and MTA so the only loss is some perf impact. I'm thinking that the right thing to do here is to remove support for ApartmentState. Thoughts? |
@SteveL-MSFT I'm not very clear about the quoted sentence. Can you please elaborate a bit on it? My understanding is that STA is for proper calls to COM object with the single-thread apartment (mainly about COM objects related to the user interface, for example, windows forms). Windows form may not be a problem as it's not supported in .NET Core. However, it may still be possible that user gets a STA COM object by A question, if we remove I want to point out that on Windows PowerShell, users are able to specify the |
|
@daxian-dbw see Interop Marshaling I'll close this for now and open a new issue regarding removing ApartmentState support and will discuss with Committee |
WSManConfigProvider doesn't work once this is enabled if starting powershell with
-sta, it does work if using-mta. The same/similar WSManConfigProvider code works fine under Windows PowerShell 5.1 withstaormta. We shouldn't have to change the WSManConfigProvider code which relies on underlying non-thread safe COM objects, but need some help debugging this.Fix #4350