[API Proposal]: Allow thread attributes in CoreLib to be applied at the assembly level. #55978
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Runtime.InteropServices
Milestone
Background and motivation
From dotnet/designs#223 (comment) all the way down to the last comment, currently RussKie is considering to do dotnet/designs#223 (comment) which is stated by @jkotas and others as being not pretty and not efficient as then the COM would then be initialized as MTA, then uninitialized, then initialized again as STA. The issue with this stems from the updated code where now you can use top level statements and skip making the
Program
class and theMain
function yourself (where those statements would be inserted inside of an compiler generatedMain
function. However the compiler does not set any thread apartment attributes by default due to issues that @jkotas also stated in a reply to me about why it cant be generated by the compiler for theMain
functions it generates for top level statements for all types of applications as stated here dotnet/designs#223 (comment).API Proposal
API Usage
As for their usage, they can be source generated by the .NET SDK:
For example the normal .NET SDK's (
UseWinForms
, andUseWPF
is not set or set tofalse
) it would generate:However when one of those properties are set the .NET SDK can instead generate:
Risks
The risk should be minimal as the .NET SDK would use this change to generate code that uses the attributes at the assembly level for the user. However it is needed in .NET 6 with those Windows Forms design changes that was merged in. This is to avoid those inefficient workarounds that would then be struck in the LTS release and it would produce more problems than good to just do this change to avoid said hacks for the UI frameworks (WPF and WinForms) to use COM properly.
The text was updated successfully, but these errors were encountered: