Skip to content

Commit

Permalink
Make System.Transactions.Local trimmable on Windows (#75176) (#75377)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
eerhardt authored Sep 12, 2022
1 parent 87dc10e commit f9b38e8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<linker>
<assembly fullname="System.Transactions.Local">
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Transactions.DtcProxyShim.DtcProxyShimFactory.ConnectToProxyCore(System.String,System.Guid,System.Object,System.Boolean@,System.Byte[]@,System.Transactions.DtcProxyShim.ResourceManagerShim@)</property>
<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>
</attribute>
</assembly>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)</TargetFrameworks>
<NoWarn>CA1805;IDE0059;CS1591</NoWarn>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<IsTrimmable Condition="'$(TargetPlatformIdentifier)' == 'windows'">false</IsTrimmable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Transactions\CommittableTransaction.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ private static extern void DtcGetTransactionManagerExW(
object? pvConfigPararms,
[MarshalAs(UnmanagedType.Interface)] out ITransactionDispenser ppvObject);

[UnconditionalSuppressMessage("Trimming", "IL2050", Justification = "Leave me alone")]
[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.")]
private static void DtcGetTransactionManager(string? nodeName, out ITransactionDispenser localDispenser) =>
DtcGetTransactionManagerExW(nodeName, null, Guids.IID_ITransactionDispenser_Guid, 0, null, out localDispenser);

public void ConnectToProxy(
string? nodeName,
Guid resourceManagerIdentifier,
Expand All @@ -61,9 +64,22 @@ public void ConnectToProxy(
throw new PlatformNotSupportedException(SR.DistributedNotSupportOn32Bits);
}

ConnectToProxyCore(nodeName, resourceManagerIdentifier, managedIdentifier, out nodeNameMatches, out whereabouts, out resourceManagerShim);
}

private void ConnectToProxyCore(
string? nodeName,
Guid resourceManagerIdentifier,
object managedIdentifier,
out bool nodeNameMatches,
out byte[] whereabouts,
out ResourceManagerShim resourceManagerShim)
{
lock (_proxyInitLock)
{
DtcGetTransactionManagerExW(nodeName, null, Guids.IID_ITransactionDispenser_Guid, 0, null, out ITransactionDispenser? localDispenser);
#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
DtcGetTransactionManager(nodeName, out ITransactionDispenser? localDispenser);
#pragma warning restore IL2026

// Check to make sure the node name matches.
if (nodeName is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,15 @@ internal void EnlistmentCreated(TraceSourceType traceSource, EnlistmentTraceIden
}

[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}")]
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026", Justification = "Only string/int are passed")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Only string/int are passed")]
private void EnlistmentCreatedLtm(int enlistmentIdentifier, string enlistmentType, string enlistmentOptions)
{
SetActivityId(string.Empty);
WriteEvent(ENLISTMENT_CREATED_LTM_EVENTID, enlistmentIdentifier, enlistmentType, enlistmentOptions);
}

[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}")]
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026", Justification = "Only string/int are passed")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Only string/int are passed")]
private void EnlistmentCreatedOleTx(int enlistmentIdentifier, string enlistmentType, string enlistmentOptions)
{
SetActivityId(string.Empty);
Expand Down

0 comments on commit f9b38e8

Please sign in to comment.