Skip to content

Commit f9b38e8

Browse files
authored
Make System.Transactions.Local trimmable on Windows (#75176) (#75377)
* Make System.Transactions.Local trimmable on Windows Remove `IsTrimmable=false` from the project, so this assembly is still trimmed with `partial` trimming on Windows. Add a "LibraryBuild" ILLink warning, so when the distributed transaction code is not trimmed, the app developer gets a warning that it is not guaranteed to work. Fix #75031 * Fix x86 build. Move the ILLink suppression to a method that is completely trimmed on x86.
1 parent 87dc10e commit f9b38e8

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<linker>
3+
<assembly fullname="System.Transactions.Local">
4+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
5+
<argument>ILLink</argument>
6+
<argument>IL2026</argument>
7+
<property name="Scope">member</property>
8+
<property name="Target">M:System.Transactions.DtcProxyShim.DtcProxyShimFactory.ConnectToProxyCore(System.String,System.Guid,System.Object,System.Boolean@,System.Byte[]@,System.Transactions.DtcProxyShim.ResourceManagerShim@)</property>
9+
<property name="Justification">This warning is left in the product so developers get an ILLink warning when trimming an app using this transaction support</property>
10+
</attribute>
11+
</assembly>
12+
</linker>

src/libraries/System.Transactions.Local/src/System.Transactions.Local.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)</TargetFrameworks>
66
<NoWarn>CA1805;IDE0059;CS1591</NoWarn>
77
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
8-
<IsTrimmable Condition="'$(TargetPlatformIdentifier)' == 'windows'">false</IsTrimmable>
98
</PropertyGroup>
109
<ItemGroup>
1110
<Compile Include="System\Transactions\CommittableTransaction.cs" />

src/libraries/System.Transactions.Local/src/System/Transactions/DtcProxyShim/DtcProxyShimFactory.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ private static extern void DtcGetTransactionManagerExW(
4747
object? pvConfigPararms,
4848
[MarshalAs(UnmanagedType.Interface)] out ITransactionDispenser ppvObject);
4949

50-
[UnconditionalSuppressMessage("Trimming", "IL2050", Justification = "Leave me alone")]
50+
[RequiresUnreferencedCode("Distributed transactions support may not be compatible with trimming. If your program creates a distributed transaction via System.Transactions, the correctness of the application cannot be guaranteed after trimming.")]
51+
private static void DtcGetTransactionManager(string? nodeName, out ITransactionDispenser localDispenser) =>
52+
DtcGetTransactionManagerExW(nodeName, null, Guids.IID_ITransactionDispenser_Guid, 0, null, out localDispenser);
53+
5154
public void ConnectToProxy(
5255
string? nodeName,
5356
Guid resourceManagerIdentifier,
@@ -61,9 +64,22 @@ public void ConnectToProxy(
6164
throw new PlatformNotSupportedException(SR.DistributedNotSupportOn32Bits);
6265
}
6366

67+
ConnectToProxyCore(nodeName, resourceManagerIdentifier, managedIdentifier, out nodeNameMatches, out whereabouts, out resourceManagerShim);
68+
}
69+
70+
private void ConnectToProxyCore(
71+
string? nodeName,
72+
Guid resourceManagerIdentifier,
73+
object managedIdentifier,
74+
out bool nodeNameMatches,
75+
out byte[] whereabouts,
76+
out ResourceManagerShim resourceManagerShim)
77+
{
6478
lock (_proxyInitLock)
6579
{
66-
DtcGetTransactionManagerExW(nodeName, null, Guids.IID_ITransactionDispenser_Guid, 0, null, out ITransactionDispenser? localDispenser);
80+
#pragma warning disable IL2026 // This warning is left in the product so developers get an ILLink warning when trimming an app using this transaction support
81+
DtcGetTransactionManager(nodeName, out ITransactionDispenser? localDispenser);
82+
#pragma warning restore IL2026
6783

6884
// Check to make sure the node name matches.
6985
if (nodeName is not null)

src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,15 @@ internal void EnlistmentCreated(TraceSourceType traceSource, EnlistmentTraceIden
573573
}
574574

575575
[Event(ENLISTMENT_CREATED_LTM_EVENTID, Keywords = Keywords.TraceLtm, Level = EventLevel.Informational, Task = Tasks.Enlistment, Opcode = Opcodes.Create, Message = "Enlistment Created (LTM). ID is {0}, type is {1}, options is {2}")]
576-
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026", Justification = "Only string/int are passed")]
576+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Only string/int are passed")]
577577
private void EnlistmentCreatedLtm(int enlistmentIdentifier, string enlistmentType, string enlistmentOptions)
578578
{
579579
SetActivityId(string.Empty);
580580
WriteEvent(ENLISTMENT_CREATED_LTM_EVENTID, enlistmentIdentifier, enlistmentType, enlistmentOptions);
581581
}
582582

583583
[Event(ENLISTMENT_CREATED_OLETX_EVENTID, Keywords = Keywords.TraceOleTx, Level = EventLevel.Informational, Task = Tasks.Enlistment, Opcode = Opcodes.Create, Message = "Enlistment Created (OLETX). ID is {0}, type is {1}, options is {2}")]
584-
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026", Justification = "Only string/int are passed")]
584+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Only string/int are passed")]
585585
private void EnlistmentCreatedOleTx(int enlistmentIdentifier, string enlistmentType, string enlistmentOptions)
586586
{
587587
SetActivityId(string.Empty);

0 commit comments

Comments
 (0)