Skip to content

Commit 4e78844

Browse files
[release/7.0] Disable EventSource support in NativeAOT by default (#76052)
* Disable EventSource support in NativeAOT by default `DiagnosticSource` is currently not AOT compatible. If a machine-wide DiagnosticSource-related event listener is enabled (such as PerfView, or possibly even a managed VS debugging session) it activates `DiagnosticSource` code paths within the executable and basically injects a runtime failure into NativeAOT processes due to the AOT-incompatibility of the code. E.g. trying to do a `HttpClient` web request with PerfView collecting in the background causes a runtime exception to be thrown. This uses the documented switch to disable `EventSource` support (unless the user specified a different value). Indirectly, it disables `DiagnosticSource` as well. As a side effect, disabling `EventSource` drops the size of a NativeAOT-compiled Hello World from 3.48 MB to 2.85 MB 🥳. * Fix tests * Update Microsoft.Extensions.Hosting.Unit.Tests.csproj * Cherry-pick relevant parts of #76114 * Port one more test fix Co-authored-by: Michal Strehovský <[email protected]>
1 parent 228edfc commit 4e78844

File tree

11 files changed

+12
-0
lines changed

11 files changed

+12
-0
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The .NET Foundation licenses this file to you under the MIT license.
4747
<PropertyGroup>
4848
<UseSystemResourceKeys Condition="$(IlcDisableReflection) == 'true'">true</UseSystemResourceKeys>
4949
<EventSourceSupport Condition="$(IlcDisableReflection) == 'true'">false</EventSourceSupport>
50+
<EventSourceSupport Condition="$(EventSourceSupport) == ''">false</EventSourceSupport>
5051
</PropertyGroup>
5152

5253
<PropertyGroup Condition="'$(SuppressAotAnalysisWarnings)' == 'true'">

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<EnableDefaultItems>true</EnableDefaultItems>
66
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
77
<AutoGenerateBindingRedirects Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">true</AutoGenerateBindingRedirects>
8+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
89
</PropertyGroup>
910

1011
<ItemGroup>

src/libraries/Microsoft.Extensions.Logging.EventSource/tests/Microsoft.Extensions.Logging.EventSource.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkMinimum)</TargetFrameworks>
55
<EnableDefaultItems>true</EnableDefaultItems>
6+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
67
</PropertyGroup>
78

89
<ItemGroup>

src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<EnablePreviewFeatures>true</EnablePreviewFeatures>
1010
<!-- the res/xml/network_security_config.xml file comes from the System.Net.TestData package -->
1111
<IncludeNetworkSecurityConfig Condition="'$(TargetOS)' == 'Android'">true</IncludeNetworkSecurityConfig>
12+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
1213
</PropertyGroup>
1314

1415
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->

src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<EnableLibraryImportGenerator>true</EnableLibraryImportGenerator>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<EnablePreviewFeatures>true</EnablePreviewFeatures>
8+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
89
</PropertyGroup>
910
<ItemGroup>
1011
<Compile Include="AlternateViewCollectionTest.cs" />

src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
44
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
55
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
6+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
67
</PropertyGroup>
78
<ItemGroup>
89
<Compile Include="AssemblyInfo.cs" />

src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
66
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
77
<DefineConstants>$(DefineConstants);NETWORKINFORMATION_TEST</DefineConstants>
8+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
89
</PropertyGroup>
910
<ItemGroup>
1011
<Compile Include="AssemblyInfo.cs" />

src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<!-- the res/xml/network_security_config.xml file comes from the System.Net.TestData package -->
1111
<IncludeNetworkSecurityConfig Condition="'$(TargetOS)' == 'Android'">true</IncludeNetworkSecurityConfig>
1212
<EnablePreviewFeatures>true</EnablePreviewFeatures>
13+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
1314
</PropertyGroup>
1415
<ItemGroup>
1516
<Compile Include="AssemblyInfo.cs" />

src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<!-- the res/xml/network_security_config.xml file comes from the System.Net.TestData package -->
99
<IncludeNetworkSecurityConfig Condition="'$(TargetOS)' == 'Android'">true</IncludeNetworkSecurityConfig>
1010
<EnablePreviewFeatures>true</EnablePreviewFeatures>
11+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
1112
</PropertyGroup>
1213
<ItemGroup>
1314
<Compile Include="AssemblyInfo.cs" />

src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
55
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
66
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
7+
<EventSourceSupport Condition="'$(TestNativeAot)' == 'true'">true</EventSourceSupport>
78
</PropertyGroup>
89
<ItemGroup>
910
<Compile Include="Accept.cs" />

0 commit comments

Comments
 (0)