Skip to content

Commit e18a77f

Browse files
authored
Keep Obsolete and EditorBrowsable attributes consistent between ref and src and DefineConst clean-up (#65847)
* NET5_0_OR_GREATER, NET6_0_OR_GREATER -> NETCOREAPP The minimum supported .NETCoreApp version in the repository is 6.0, hence both defines can be replaced with the versionless NETCOREAPP one. There is no need to version APIs below the minimum supported .NETCoreApp version. * Sync ObsoleteAttribute between ref and src ApiCompat wasn't enabled to check if the ObsoleteAttribute is in sync between the ref and the src assembly. Enabling it showed numerous mismatches which this commit fixes. Also making sure that the ApiCompat run that compares the live build against the previous version of .NETCoreApp and .NETStandard2.x doesn't complain about ObsoleteAttribute API changes as those are intentional. * Sync EditorBrowsableAttribute between ref and src The EditorBrowsableAttribute attribute wasn't enabled to be checked by ApiCompat and in many cases there were mismatches. The most prominent were InteropServices. * HttpListenerContext pr feedback * ResourceManager pr feedback * Json PR feedback * Fix cryptography PNSE build
1 parent ac246b1 commit e18a77f

File tree

274 files changed

+813
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+813
-444
lines changed

eng/DefaultGenApiDocIds.txt

-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,3 @@ T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute
5252
T:System.Runtime.CompilerServices.AsyncMethodBuilderAttribute
5353
T:System.Reflection.DefaultMemberAttribute
5454
T:System.Timers.TimersDescriptionAttribute
55-
56-
// These do not need to be persisted in the implementation
57-
T:System.ComponentModel.EditorBrowsableAttribute
58-
T:System.ObsoleteAttribute

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsHelper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
// means that the problem is already quite complex and we should not be dealing with it - see
8282
// ComEventsMethod.Invoke
8383

84+
using System.ComponentModel;
8485
using System.Runtime.Versioning;
8586

8687
namespace System.Runtime.InteropServices
@@ -90,6 +91,7 @@ namespace System.Runtime.InteropServices
9091
/// raised COM objects.
9192
/// </summary>
9293
[SupportedOSPlatform("windows")]
94+
[EditorBrowsable(EditorBrowsableState.Never)]
9395
public static class ComEventsHelper
9496
{
9597
/// <summary>

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs

+32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.ComponentModel;
45
using System.Diagnostics.CodeAnalysis;
56
using System.Reflection;
67
using System.Runtime.CompilerServices;
@@ -28,6 +29,7 @@ public static partial class Marshal
2829

2930
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
3031
Justification = "Trimming doesn't affect types eligible for marshalling. Different exception for invalid inputs doesn't matter.")]
32+
[EditorBrowsable(EditorBrowsableState.Never)]
3133
public static IntPtr OffsetOf(Type t!!, string fieldName)
3234
{
3335
FieldInfo? f = t.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
@@ -48,24 +50,32 @@ public static IntPtr OffsetOf(Type t!!, string fieldName)
4850
[MethodImpl(MethodImplOptions.InternalCall)]
4951
private static extern IntPtr OffsetOfHelper(IRuntimeFieldInfo f);
5052

53+
[EditorBrowsable(EditorBrowsableState.Never)]
54+
[Obsolete("ReadByte(Object, Int32) may be unavailable in future releases.")]
5155
[RequiresDynamicCode("Marshalling code for the object might not be available")]
5256
public static byte ReadByte(object ptr, int ofs)
5357
{
5458
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadByte(nativeHome, offset));
5559
}
5660

61+
[EditorBrowsable(EditorBrowsableState.Never)]
62+
[Obsolete("ReadInt16(Object, Int32) may be unavailable in future releases.")]
5763
[RequiresDynamicCode("Marshalling code for the object might not be available")]
5864
public static short ReadInt16(object ptr, int ofs)
5965
{
6066
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt16(nativeHome, offset));
6167
}
6268

69+
[EditorBrowsable(EditorBrowsableState.Never)]
70+
[Obsolete("ReadInt32(Object, Int32) may be unavailable in future releases.")]
6371
[RequiresDynamicCode("Marshalling code for the object might not be available")]
6472
public static int ReadInt32(object ptr, int ofs)
6573
{
6674
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt32(nativeHome, offset));
6775
}
6876

77+
[EditorBrowsable(EditorBrowsableState.Never)]
78+
[Obsolete("ReadInt64(Object, Int32) may be unavailable in future releases.")]
6979
[RequiresDynamicCode("Marshalling code for the object might not be available")]
7080
public static long ReadInt64([MarshalAs(UnmanagedType.AsAny), In] object ptr, int ofs)
7181
{
@@ -106,24 +116,32 @@ private static unsafe T ReadValueSlow<T>(object ptr, int ofs, Func<IntPtr, int,
106116
}
107117
}
108118

119+
[EditorBrowsable(EditorBrowsableState.Never)]
120+
[Obsolete("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")]
109121
[RequiresDynamicCode("Marshalling code for the object might not be available")]
110122
public static void WriteByte(object ptr, int ofs, byte val)
111123
{
112124
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, byte value) => WriteByte(nativeHome, offset, value));
113125
}
114126

127+
[EditorBrowsable(EditorBrowsableState.Never)]
128+
[Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
115129
[RequiresDynamicCode("Marshalling code for the object might not be available")]
116130
public static void WriteInt16(object ptr, int ofs, short val)
117131
{
118132
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, short value) => Marshal.WriteInt16(nativeHome, offset, value));
119133
}
120134

135+
[EditorBrowsable(EditorBrowsableState.Never)]
136+
[Obsolete("WriteInt32(Object, Int32, Int32) may be unavailable in future releases.")]
121137
[RequiresDynamicCode("Marshalling code for the object might not be available")]
122138
public static void WriteInt32(object ptr, int ofs, int val)
123139
{
124140
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, int value) => Marshal.WriteInt32(nativeHome, offset, value));
125141
}
126142

143+
[EditorBrowsable(EditorBrowsableState.Never)]
144+
[Obsolete("WriteInt64(Object, Int32, Int64) may be unavailable in future releases.")]
127145
[RequiresDynamicCode("Marshalling code for the object might not be available")]
128146
public static void WriteInt64(object ptr, int ofs, long val)
129147
{
@@ -201,6 +219,8 @@ private static void PrelinkCore(MethodInfo m)
201219
[MethodImpl(MethodImplOptions.InternalCall)]
202220
public static extern /* struct _EXCEPTION_POINTERS* */ IntPtr GetExceptionPointers();
203221

222+
[EditorBrowsable(EditorBrowsableState.Never)]
223+
[Obsolete("GetExceptionCode() may be unavailable in future releases.")]
204224
[MethodImpl(MethodImplOptions.InternalCall)]
205225
public static extern int GetExceptionCode();
206226

@@ -211,6 +231,7 @@ private static void PrelinkCore(MethodInfo m)
211231
/// </summary>
212232
[RequiresDynamicCode("Marshalling code for the object might not be available. Use the StructureToPtr<T> overload instead.")]
213233
[MethodImpl(MethodImplOptions.InternalCall)]
234+
[EditorBrowsable(EditorBrowsableState.Never)]
214235
public static extern void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld);
215236

216237
/// <summary>
@@ -225,6 +246,7 @@ private static void PrelinkCore(MethodInfo m)
225246
/// </summary>
226247
[RequiresDynamicCode("Marshalling code for the object might not be available. Use the DestroyStructure<T> overload instead.")]
227248
[MethodImpl(MethodImplOptions.InternalCall)]
249+
[EditorBrowsable(EditorBrowsableState.Never)]
228250
public static extern void DestroyStructure(IntPtr ptr, Type structuretype);
229251

230252
[MethodImpl(MethodImplOptions.InternalCall)]
@@ -327,6 +349,7 @@ public static string GetTypeInfoName(ITypeInfo typeInfo!!)
327349
/// Object o should support Type T
328350
/// </summary>
329351
[SupportedOSPlatform("windows")]
352+
[EditorBrowsable(EditorBrowsableState.Never)]
330353
public static IntPtr /* IUnknown* */ GetComInterfaceForObject(object o!!, Type T!!)
331354
{
332355
return GetComInterfaceForObjectNative(o, T, true);
@@ -341,6 +364,7 @@ public static string GetTypeInfoName(ITypeInfo typeInfo!!)
341364
/// invoke customized QueryInterface or not.
342365
/// </summary>
343366
[SupportedOSPlatform("windows")]
367+
[EditorBrowsable(EditorBrowsableState.Never)]
344368
public static IntPtr /* IUnknown* */ GetComInterfaceForObject(object o!!, Type T!!, CustomQueryInterfaceMode mode)
345369
{
346370
bool bEnableCustomizedQueryInterface = ((mode == CustomQueryInterfaceMode.Allow) ? true : false);
@@ -390,6 +414,7 @@ public static object GetUniqueObjectForIUnknown(IntPtr unknown)
390414
public static extern object GetTypedObjectForIUnknown(IntPtr /* IUnknown* */ pUnk, Type t);
391415

392416
[SupportedOSPlatform("windows")]
417+
[EditorBrowsable(EditorBrowsableState.Never)]
393418
public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
394419
{
395420
if (!IsBuiltInComSupported)
@@ -530,6 +555,7 @@ public static bool SetComObjectData(object obj, object key, object? data)
530555
/// of the specified type. The type must be derived from __ComObject.
531556
/// </summary>
532557
[SupportedOSPlatform("windows")]
558+
[EditorBrowsable(EditorBrowsableState.Never)]
533559
[return: NotNullIfNotNull("o")]
534560
public static object? CreateWrapperOfType(object? o, Type t)
535561
{
@@ -603,6 +629,7 @@ public static TWrapper CreateWrapperOfType<T, TWrapper>(T? o)
603629
public static extern bool IsTypeVisibleFromCom(Type t);
604630

605631
[SupportedOSPlatform("windows")]
632+
[EditorBrowsable(EditorBrowsableState.Never)]
606633
public static void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant)
607634
{
608635
if (!IsBuiltInComSupported)
@@ -617,6 +644,7 @@ public static void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr
617644
private static extern void GetNativeVariantForObjectNative(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant);
618645

619646
[SupportedOSPlatform("windows")]
647+
[EditorBrowsable(EditorBrowsableState.Never)]
620648
public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant)
621649
{
622650
if (!IsBuiltInComSupported)
@@ -628,6 +656,7 @@ public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant
628656
}
629657

630658
[SupportedOSPlatform("windows")]
659+
[EditorBrowsable(EditorBrowsableState.Never)]
631660
public static object? GetObjectForNativeVariant(/* VARIANT * */ IntPtr pSrcNativeVariant)
632661
{
633662
if (!IsBuiltInComSupported)
@@ -642,6 +671,7 @@ public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant
642671
private static extern object? GetObjectForNativeVariantNative(/* VARIANT * */ IntPtr pSrcNativeVariant);
643672

644673
[SupportedOSPlatform("windows")]
674+
[EditorBrowsable(EditorBrowsableState.Never)]
645675
public static T? GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
646676
{
647677
if (!IsBuiltInComSupported)
@@ -653,6 +683,7 @@ public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant
653683
}
654684

655685
[SupportedOSPlatform("windows")]
686+
[EditorBrowsable(EditorBrowsableState.Never)]
656687
public static object?[] GetObjectsForNativeVariants(/* VARIANT * */ IntPtr aSrcNativeVariant, int cVars)
657688
{
658689
if (!IsBuiltInComSupported)
@@ -667,6 +698,7 @@ public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant
667698
private static extern object?[] GetObjectsForNativeVariantsNative(/* VARIANT * */ IntPtr aSrcNativeVariant, int cVars);
668699

669700
[SupportedOSPlatform("windows")]
701+
[EditorBrowsable(EditorBrowsableState.Never)]
670702
public static T[] GetObjectsForNativeVariants<T>(IntPtr aSrcNativeVariant, int cVars)
671703
{
672704
if (!IsBuiltInComSupported)

src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs

+4
Original file line numberDiff line numberDiff line change
@@ -3887,9 +3887,11 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType
38873887
case DispatchWrapperType.Error:
38883888
wrapperType = typeof(ErrorWrapper);
38893889
break;
3890+
#pragma warning disable 0618 // CurrencyWrapper is obsolete
38903891
case DispatchWrapperType.Currency:
38913892
wrapperType = typeof(CurrencyWrapper);
38923893
break;
3894+
#pragma warning restore 0618
38933895
case DispatchWrapperType.BStr:
38943896
wrapperType = typeof(BStrWrapper);
38953897
isString = true;
@@ -3946,9 +3948,11 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType
39463948
case DispatchWrapperType.Error:
39473949
aArgs[i] = new ErrorWrapper(aArgs[i]);
39483950
break;
3951+
#pragma warning disable 0618 // CurrencyWrapper is obsolete
39493952
case DispatchWrapperType.Currency:
39503953
aArgs[i] = new CurrencyWrapper(aArgs[i]);
39513954
break;
3955+
#pragma warning restore 0618
39523956
case DispatchWrapperType.BStr:
39533957
aArgs[i] = new BStrWrapper((string)aArgs[i]);
39543958
break;

src/coreclr/System.Private.CoreLib/src/System/Variant.cs

+4
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,14 @@ public Variant(object? obj)
288288
obj = (object)(((ErrorWrapper)obj).ErrorCode);
289289
Debug.Assert(obj != null, "obj != null");
290290
}
291+
#pragma warning disable 0618 // CurrencyWrapper is obsolete
291292
else if (obj is CurrencyWrapper)
292293
{
293294
vt = VarEnum.VT_CY;
294295
obj = (object)(((CurrencyWrapper)obj).WrappedObject);
295296
Debug.Assert(obj != null, "obj != null");
296297
}
298+
#pragma warning restore 0618
297299
else if (obj is BStrWrapper)
298300
{
299301
vt = VarEnum.VT_BSTR;
@@ -441,7 +443,9 @@ internal static void MarshalHelperCastVariant(object pValue, int vt, ref Variant
441443
3 => /*VT_I4*/ new Variant(iv.ToInt32(provider)),
442444
4 => /*VT_R4*/ new Variant(iv.ToSingle(provider)),
443445
5 => /*VT_R8*/ new Variant(iv.ToDouble(provider)),
446+
#pragma warning disable 0618 // CurrencyWrapper is obsolete
444447
6 => /*VT_CY*/ new Variant(new CurrencyWrapper(iv.ToDecimal(provider))),
448+
#pragma warning restore 0618
445449
7 => /*VT_DATE*/ new Variant(iv.ToDateTime(provider)),
446450
8 => /*VT_BSTR*/ new Variant(iv.ToString(provider)),
447451
#pragma warning disable CA1416 // Validate platform compatibility

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.CoreRT.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static Assembly Load(string assemblyString)
3636
return Load(name);
3737
}
3838

39-
[Obsolete("This method has been deprecated. Please use Assembly.Load() instead. https://go.microsoft.com/fwlink/?linkid=14202")]
39+
[Obsolete("Assembly.LoadWithPartialName has been deprecated. Use Assembly.Load() instead.")]
4040
public static Assembly LoadWithPartialName(string partialName)
4141
{
4242
if (partialName == null)

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsHelper.CoreRT.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.ComponentModel;
45
using System.Runtime.Versioning;
56

67
namespace System.Runtime.InteropServices
78
{
89
[SupportedOSPlatform("windows")]
10+
[EditorBrowsable(EditorBrowsableState.Never)]
911
public static class ComEventsHelper
1012
{
1113
public static void Combine(object rcw, Guid iid, int dispid, Delegate d)

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Com.cs

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.ComponentModel;
45
using System.Diagnostics.CodeAnalysis;
56
using System.Reflection;
67
using System.Runtime.InteropServices.ComTypes;
@@ -24,6 +25,7 @@ public static int GetHRForException(Exception? e)
2425
public static bool AreComObjectsAvailableForCleanup() => false;
2526

2627
[SupportedOSPlatform("windows")]
28+
[EditorBrowsable(EditorBrowsableState.Never)]
2729
public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
2830
{
2931
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
@@ -47,6 +49,7 @@ public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : not
4749
}
4850

4951
[SupportedOSPlatform("windows")]
52+
[EditorBrowsable(EditorBrowsableState.Never)]
5053
public static object? CreateWrapperOfType(object? o, Type t)
5154
{
5255
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
@@ -71,6 +74,7 @@ public static int FinalReleaseComObject(object o)
7174
}
7275

7376
[SupportedOSPlatform("windows")]
77+
[EditorBrowsable(EditorBrowsableState.Never)]
7478
public static IntPtr GetComInterfaceForObject(object o, Type T)
7579
{
7680
if (o is null)
@@ -87,6 +91,7 @@ public static IntPtr GetComInterfaceForObject(object o, Type T)
8791
}
8892

8993
[SupportedOSPlatform("windows")]
94+
[EditorBrowsable(EditorBrowsableState.Never)]
9095
public static IntPtr GetComInterfaceForObject(object o, Type T, CustomQueryInterfaceMode mode)
9196
{
9297
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
@@ -122,6 +127,7 @@ public static IntPtr GetIUnknownForObject(object o)
122127
}
123128

124129
[SupportedOSPlatform("windows")]
130+
[EditorBrowsable(EditorBrowsableState.Never)]
125131
public static unsafe void GetNativeVariantForObject(object? obj, IntPtr pDstNativeVariant)
126132
{
127133
if (pDstNativeVariant == IntPtr.Zero)
@@ -188,9 +194,11 @@ public static unsafe void GetNativeVariantForObject(object? obj, IntPtr pDstNati
188194
case BStrWrapper value:
189195
data->AsBstr = value.WrappedObject;
190196
break;
197+
#pragma warning disable 0618 // CurrencyWrapper is obsolete
191198
case CurrencyWrapper value:
192199
data->AsCy = value.WrappedObject;
193200
break;
201+
#pragma warning restore 0618
194202
case UnknownWrapper value:
195203
data->AsUnknown = value.WrappedObject;
196204
break;
@@ -285,6 +293,7 @@ public static unsafe void GetNativeVariantForObject(object? obj, IntPtr pDstNati
285293
}
286294

287295
[SupportedOSPlatform("windows")]
296+
[EditorBrowsable(EditorBrowsableState.Never)]
288297
public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant)
289298
{
290299
GetNativeVariantForObject((object?)obj, pDstNativeVariant);
@@ -303,6 +312,7 @@ public static object GetObjectForIUnknown(IntPtr pUnk)
303312
}
304313

305314
[SupportedOSPlatform("windows")]
315+
[EditorBrowsable(EditorBrowsableState.Never)]
306316
public static unsafe object? GetObjectForNativeVariant(IntPtr pSrcNativeVariant)
307317
{
308318
if (pSrcNativeVariant == IntPtr.Zero)
@@ -351,18 +361,21 @@ public static object GetObjectForIUnknown(IntPtr pUnk)
351361

352362
[return: MaybeNull]
353363
[SupportedOSPlatform("windows")]
364+
[EditorBrowsable(EditorBrowsableState.Never)]
354365
public static T GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
355366
{
356367
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
357368
}
358369

359370
[SupportedOSPlatform("windows")]
371+
[EditorBrowsable(EditorBrowsableState.Never)]
360372
public static object?[] GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
361373
{
362374
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
363375
}
364376

365377
[SupportedOSPlatform("windows")]
378+
[EditorBrowsable(EditorBrowsableState.Never)]
366379
public static T[] GetObjectsForNativeVariants<T>(IntPtr aSrcNativeVariant, int cVars)
367380
{
368381
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);

0 commit comments

Comments
 (0)