Skip to content
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

Add NetCoreAppCurrent configuration to three ref projects #54146

Merged
merged 4 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.1;netstandard2.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.ComponentModel.Composition.cs" />
<Compile Include="System.ComponentModel.Composition.Forwards.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Linq.Expressions\ref\System.Linq.Expressions.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<Reference Include="System.Linq.Expressions" />
<Reference Include="System.Runtime" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net461</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.1;netstandard2.0;net461</TargetFrameworks>
akoeplinger marked this conversation as resolved.
Show resolved Hide resolved
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Condition="'$(TargetFramework)' != 'net461'" Include="System.Diagnostics.PerformanceCounter.cs" />
<Compile Condition="'$(TargetFramework)' == 'net461'" Include="System.Diagnostics.PerformanceCounter.net461.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections.NonGeneric\ref\System.Collections.NonGeneric.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.ComponentModel.Primitives\ref\System.ComponentModel.Primitives.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<Reference Include="System.Collections.NonGeneric" />
<Reference Include="System.ComponentModel.Primitives" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;netcoreapp3.1-windows;netcoreapp3.1;netstandard2.0;net461</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);netcoreapp3.1-windows;netcoreapp3.1;netstandard2.0;net461</TargetFrameworks>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.1;netstandard2.0</TargetFrameworks>
akoeplinger marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Runtime.Caching.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections\ref\System.Collections.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections.Specialized\ref\System.Collections.Specialized.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.ComponentModel\ref\System.ComponentModel.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Specialized" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;netcoreapp3.1-windows;netcoreapp3.1;netstandard2.0-windows;netstandard2.0</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);netcoreapp3.1-windows;netcoreapp3.1;netstandard2.0-windows;netstandard2.0</TargetFrameworks>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

using System;
using System.Configuration;
using System.Runtime.Versioning;

namespace System.Runtime.Caching.Configuration
{
#if NET5_0_OR_GREATER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually don't ifdef and just set this property (in this case in the src csproj) to include the platform attributes on downstream tfms: <IncludePlatformAttributes>true</IncludePlatformAttributes>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already set that propery, but it's not enough here because browser is not recognized as a valid platform on these downstream tfms and the build would fail with:

error CA1418: The platform 'browser' is not a known platform name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@buyaa-n is that expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is, maybe we should disable the CA1418 for TFMs below 5.0

[UnsupportedOSPlatform("browser")]
#endif
internal sealed class CachingSectionGroup : ConfigurationSectionGroup
{
public CachingSectionGroup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
using System;
using System.ComponentModel;
using System.Configuration;
using System.Runtime.Versioning;

namespace System.Runtime.Caching.Configuration
{
#if NET5_0_OR_GREATER
[UnsupportedOSPlatform("browser")]
#endif
internal sealed class MemoryCacheElement : ConfigurationElement
{
private static readonly ConfigurationProperty s_propName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Specialized;
using System.Configuration;
using System.Runtime.Caching.Resources;
using System.Runtime.Versioning;

namespace System.Runtime.Caching.Configuration
{
Expand All @@ -20,6 +21,9 @@ namespace System.Runtime.Caching.Configuration
</system.caching>
*/

#if NET5_0_OR_GREATER
[UnsupportedOSPlatform("browser")]
#endif
internal sealed class MemoryCacheSection : ConfigurationSection
{
private static readonly ConfigurationProperty s_propNamedCaches = new ConfigurationProperty("namedCaches",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

using System;
using System.Configuration;
using System.Runtime.Versioning;

namespace System.Runtime.Caching.Configuration
{
#if NET5_0_OR_GREATER
[UnsupportedOSPlatform("browser")]
#endif
[ConfigurationCollection(typeof(MemoryCacheElement),
CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
internal sealed class MemoryCacheSettingsCollection : ConfigurationElementCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Threading;
using System.Runtime.Versioning;

namespace System.Runtime.Caching
{
#if NET5_0_OR_GREATER
[UnsupportedOSPlatform("browser")]
#endif
internal sealed class Counters : EventSource
{
#if NETCOREAPP3_1_OR_GREATER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
using System.Collections;
using System.IO;
using System.Security;
using System.Runtime.Versioning;

namespace System.Runtime.Caching
{
#if NET5_0_OR_GREATER
[UnsupportedOSPlatform("browser")]
#endif
internal sealed class FileChangeNotificationSystem : IFileChangeNotificationSystem
{
private readonly Hashtable _dirMonitors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ private static void InitFCN()
}
if (fcn == null)
{
#if NET5_0_OR_GREATER
if (OperatingSystem.IsBrowser())
{
throw new PlatformNotSupportedException();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this method should have annotated with [UnsupportedOSPlatform("browser")] ?

Copy link
Member Author

@akoeplinger akoeplinger Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because you could implement your own custom version of IFileChangeNotificationSystem that works on browser and pass it in via ObjectCache.Host. We should only throw when we're using the default implementation.

}
#endif

fcn = new FileChangeNotificationSystem();
}
Interlocked.CompareExchange(ref s_fcn, fcn, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Security;
using System.Threading;
using System.Diagnostics;
using System.Runtime.Versioning;

namespace System.Runtime.Caching
{
Expand All @@ -38,6 +39,12 @@ public class MemoryCache : ObjectCache, IEnumerable, IDisposable
private bool _useMemoryCacheManager = true;
private EventHandler _onAppDomainUnload;
private UnhandledExceptionEventHandler _onUnhandledException;
#if NET5_0_OR_GREATER
[UnsupportedOSPlatformGuard("browser")]
private static bool _countersSupported => !OperatingSystem.IsBrowser();
#else
private static bool _countersSupported => true;
#endif

private bool IsDisposed { get { return (_disposed == 1); } }
internal bool ConfigLess { get { return _configLess; } }
Expand Down Expand Up @@ -196,7 +203,10 @@ private void InitDisposableMembers(NameValueCollection config)
{
try
{
_perfCounters = new Counters(_name);
if (_countersSupported)
{
_perfCounters = new Counters(_name);
}
}
catch
{
Expand Down Expand Up @@ -481,7 +491,10 @@ public void Dispose()
}
if (_perfCounters != null)
{
_perfCounters.Dispose();
if (_countersSupported)
{
_perfCounters.Dispose();
}
}
GC.SuppressFinalize(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Runtime.Caching.Configuration;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Threading;

Expand Down Expand Up @@ -36,6 +37,12 @@ internal sealed class MemoryCacheStatistics : IDisposable
private CacheMemoryMonitor _cacheMemoryMonitor;
private readonly MemoryCache _memoryCache;
private readonly PhysicalMemoryMonitor _physicalMemoryMonitor;
#if NET5_0_OR_GREATER
[UnsupportedOSPlatformGuard("browser")]
private static bool _configSupported => !OperatingSystem.IsBrowser();
#else
private static bool _configSupported => true;
#endif

// private

Expand Down Expand Up @@ -117,7 +124,7 @@ private int GetPercentToTrim()
private void InitializeConfiguration(NameValueCollection config)
{
MemoryCacheElement element = null;
if (!_memoryCache.ConfigLess)
if (!_memoryCache.ConfigLess && _configSupported)
{
MemoryCacheSection section = ConfigurationManager.GetSection("system.runtime.caching/memoryCache") as MemoryCacheSection;
if (section != null)
Expand All @@ -126,7 +133,7 @@ private void InitializeConfiguration(NameValueCollection config)
}
}

if (element != null)
if (element != null && _configSupported)
{
_configCacheMemoryLimitMegabytes = element.CacheMemoryLimitMegabytes;
_configPhysicalMemoryLimitPercentage = element.PhysicalMemoryLimitPercentage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.Security;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Versioning;

namespace System.Runtime.Caching
{
Expand All @@ -25,6 +26,12 @@ internal sealed class MemoryCacheStore : IDisposable
private volatile bool _useInsertBlock;
private readonly MemoryCache _cache;
private readonly Counters _perfCounters;
#if NET5_0_OR_GREATER
[UnsupportedOSPlatformGuard("browser")]
private static bool _countersSupported => !OperatingSystem.IsBrowser();
#else
private static bool _countersSupported => true;
#endif

internal MemoryCacheStore(MemoryCache cache, Counters perfCounters)
{
Expand Down Expand Up @@ -73,7 +80,7 @@ private void AddToCache(MemoryCacheEntry entry)
}

entry.CallNotifyOnChanged();
if (_perfCounters != null)
if (_perfCounters != null && _countersSupported)
{
_perfCounters.Increment(CounterName.Entries);
_perfCounters.Increment(CounterName.Turnover);
Expand Down Expand Up @@ -108,7 +115,7 @@ private void RemoveFromCache(MemoryCacheEntry entry, CacheEntryRemovedReason rea
{
entry.Release(_cache, reason);
}
if (_perfCounters != null)
if (_perfCounters != null && _countersSupported)
{
_perfCounters.Decrement(CounterName.Entries);
_perfCounters.Increment(CounterName.Turnover);
Expand Down Expand Up @@ -136,7 +143,7 @@ internal void UpdateExpAndUsage(MemoryCacheEntry entry, bool updatePerfCounters
// keep the sentinel from expiring, which in turn would force a removal of this entry from the cache.
entry.UpdateSlidingExpForUpdateSentinel();

if (updatePerfCounters && _perfCounters != null)
if (updatePerfCounters && _perfCounters != null && _countersSupported)
{
_perfCounters.Increment(CounterName.Hits);
_perfCounters.Increment(CounterName.HitRatio);
Expand All @@ -145,7 +152,7 @@ internal void UpdateExpAndUsage(MemoryCacheEntry entry, bool updatePerfCounters
}
else
{
if (updatePerfCounters && _perfCounters != null)
if (updatePerfCounters && _perfCounters != null && _countersSupported)
{
_perfCounters.Increment(CounterName.Misses);
_perfCounters.Increment(CounterName.HitRatioBase);
Expand Down Expand Up @@ -404,7 +411,7 @@ internal long TrimInternal(int percent)
trimmedOrExpired += trimmed;
}

if (trimmed > 0 && _perfCounters != null)
if (trimmed > 0 && _perfCounters != null && _countersSupported)
{
// Update values for perfcounters
_perfCounters.IncrementBy(CounterName.Trims, trimmed);
Expand Down