Skip to content

Commit 175917c

Browse files
authored
Fix RequiresDynamicCode warnings in OleDb (#118624)
This specifically addresses IL3050 warnings (ones generated as part of AOT-compat). Contributes to #75480
1 parent e914183 commit 175917c

18 files changed

+102
-22
lines changed

src/libraries/System.Data.OleDb/ref/System.Data.OleDb.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace System.Data.OleDb
88
{
99
[System.ComponentModel.DesignerAttribute("Microsoft.VSDesigner.Data.VS.OleDbCommandDesigner, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
1010
[System.ComponentModel.ToolboxItemAttribute(true)]
11+
#if NET
12+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
13+
#endif
1114
public sealed partial class OleDbCommand : System.Data.Common.DbCommand, System.Data.IDbCommand, System.ICloneable, System.IDisposable
1215
{
1316
public OleDbCommand() { }
@@ -81,6 +84,9 @@ protected override void SetRowUpdatingHandler(System.Data.Common.DbDataAdapter a
8184
public string UnquoteIdentifier(string quotedIdentifier, System.Data.OleDb.OleDbConnection? connection) { throw null; }
8285
}
8386
[System.ComponentModel.DefaultEventAttribute("InfoMessage")]
87+
#if NET
88+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
89+
#endif
8490
public sealed partial class OleDbConnection : System.Data.Common.DbConnection, System.Data.IDbConnection, System.ICloneable, System.IDisposable
8591
{
8692
public OleDbConnection() { }
@@ -127,6 +133,9 @@ public void ResetState() { }
127133
}
128134
[System.ComponentModel.DefaultPropertyAttribute("Provider")]
129135
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
136+
#if NET
137+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
138+
#endif
130139
public sealed partial class OleDbConnectionStringBuilder : System.Data.Common.DbConnectionStringBuilder
131140
{
132141
public OleDbConnectionStringBuilder() { }
@@ -151,6 +160,9 @@ public override void Clear() { }
151160
}
152161
[System.ComponentModel.DesignerAttribute("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterDesigner, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
153162
[System.ComponentModel.ToolboxItemAttribute("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterToolboxItem, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
163+
#if NET
164+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
165+
#endif
154166
public sealed partial class OleDbDataAdapter : System.Data.Common.DbDataAdapter, System.Data.IDataAdapter, System.Data.IDbDataAdapter, System.ICloneable
155167
{
156168
public OleDbDataAdapter() { }
@@ -183,6 +195,9 @@ protected override void OnRowUpdated(System.Data.Common.RowUpdatedEventArgs valu
183195
protected override void OnRowUpdating(System.Data.Common.RowUpdatingEventArgs value) { }
184196
object System.ICloneable.Clone() { throw null; }
185197
}
198+
#if NET
199+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
200+
#endif
186201
public sealed partial class OleDbDataReader : System.Data.Common.DbDataReader
187202
{
188203
internal OleDbDataReader() { }
@@ -229,8 +244,17 @@ public override void Close() { }
229244
public sealed partial class OleDbEnumerator
230245
{
231246
public OleDbEnumerator() { }
247+
#if NET
248+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
249+
#endif
232250
public System.Data.DataTable GetElements() { throw null; }
251+
#if NET
252+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
253+
#endif
233254
public static System.Data.OleDb.OleDbDataReader GetEnumerator(System.Type type) { throw null; }
255+
#if NET
256+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
257+
#endif
234258
public static System.Data.OleDb.OleDbDataReader GetRootEnumerator() { throw null; }
235259
}
236260
public sealed partial class OleDbError
@@ -265,6 +289,9 @@ internal OleDbException() { }
265289
#endif
266290
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo si, System.Runtime.Serialization.StreamingContext context) { }
267291
}
292+
#if NET
293+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
294+
#endif
268295
public sealed partial class OleDbFactory : System.Data.Common.DbProviderFactory
269296
{
270297
internal OleDbFactory() { }
@@ -477,6 +504,9 @@ public sealed partial class OleDbSchemaGuid
477504
public static readonly System.Guid View_Table_Usage;
478505
public OleDbSchemaGuid() { }
479506
}
507+
#if NET
508+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("OleDbConnection is not AOT-compatible.")]
509+
#endif
480510
public sealed partial class OleDbTransaction : System.Data.Common.DbTransaction
481511
{
482512
internal OleDbTransaction() { }

src/libraries/System.Data.OleDb/src/OleDbCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace System.Data.OleDb
1414
{
1515
[Designer("Microsoft.VSDesigner.Data.VS.OleDbCommandDesigner, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
1616
[ToolboxItem(true)]
17+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
1718
public sealed class OleDbCommand : DbCommand, ICloneable, IDbCommand
1819
{
1920
// command data

src/libraries/System.Data.OleDb/src/OleDbConnection.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ namespace System.Data.OleDb
1919
// it won't happen if you directly create the provider and set its properties
2020
// 2. First call on IDBInitialize must be Initialize, can't QI for any other interfaces before that
2121
[DefaultEvent("InfoMessage")]
22+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
2223
public sealed partial class OleDbConnection : DbConnection, ICloneable, IDbConnection
2324
{
25+
internal const string TrimWarning = "OleDbConnection is not AOT-compatible.";
26+
2427
private static readonly object EventInfoMessage = new object();
2528

2629
public OleDbConnection(string? connectionString) : this()

src/libraries/System.Data.OleDb/src/OleDbConnectionFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
using System.Data.Common;
77
using System.Data.ProviderBase;
88
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
910
using System.IO;
1011
using System.Runtime.Versioning;
1112

1213
namespace System.Data.OleDb
1314
{
15+
[RequiresDynamicCode("XML deserialization requires dynamic code")]
1416
internal sealed class OleDbConnectionFactory : DbConnectionFactory
1517
{
1618
private OleDbConnectionFactory() : base() { }

src/libraries/System.Data.OleDb/src/OleDbConnectionInternal.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
using System.Data.Common;
66
using System.Data.ProviderBase;
77
using System.Diagnostics;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.Globalization;
910
using System.Runtime.InteropServices;
1011
using System.Threading;
1112
using SysTx = System.Transactions;
1213

1314
namespace System.Data.OleDb
1415
{
16+
#if NET
17+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
18+
#endif
1519
internal sealed class OleDbConnectionInternal : DbConnectionInternal, IDisposable
1620
{
1721
private static volatile OleDbServicesWrapper? idataInitialize;
@@ -414,7 +418,11 @@ internal void EnlistTransactionInternal(SysTx.Transaction? transaction)
414418
tagDBLITERALINFO tag = new tagDBLITERALINFO();
415419
for (int i = 0; i < literalCount; ++i, offset += ODB.SizeOf_tagDBLITERALINFO)
416420
{
417-
Marshal.PtrToStructure((nint)offset, tag);
421+
if (offset is null)
422+
{
423+
throw new NullReferenceException();
424+
}
425+
tag = Marshal.PtrToStructure<tagDBLITERALINFO>((IntPtr)offset)!;
418426

419427
DataRow row = table.NewRow();
420428
row[literalName] = ((OleDbLiteral)tag.it).ToString();
@@ -591,7 +599,7 @@ internal DataTable BuildSchemaGuids()
591599
for (int i = 0, offset = 0; i < supportedSchemas.Length; ++i, offset += ODB.SizeOf_Guid)
592600
{
593601
IntPtr ptr = ADP.IntPtrOffset(schemaGuids, i * ODB.SizeOf_Guid);
594-
supportedSchemas[i]._schemaRowset = (Guid)Marshal.PtrToStructure(ptr, typeof(Guid))!;
602+
supportedSchemas[i]._schemaRowset = Marshal.PtrToStructure<Guid>(ptr)!;
595603
}
596604
}
597605
if (IntPtr.Zero != schemaRestrictions)

src/libraries/System.Data.OleDb/src/OleDbConnectionStringBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace System.Data.OleDb
1515
[DefaultProperty("Provider")]
1616
[RefreshProperties(RefreshProperties.All)]
1717
[TypeConverter(typeof(OleDbConnectionStringBuilder.OleDbConnectionStringBuilderConverter))]
18+
#if NET
19+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
20+
#endif
1821
public sealed class OleDbConnectionStringBuilder : DbConnectionStringBuilder
1922
{
2023
private enum Keywords
@@ -528,6 +531,7 @@ private Dictionary<string, OleDbPropertyInfo> GetProviderInfo(string provider)
528531
return providerInfo;
529532
}
530533

534+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
531535
private sealed class OleDbProviderConverter : StringConverter
532536
{
533537
private const int DBSOURCETYPE_DATASOURCE_TDP = 1;
@@ -599,6 +603,7 @@ internal enum OleDbServiceValues : int
599603
Default = ~(ClientCursor | AggregationAfterSession),
600604
};
601605

606+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
602607
internal sealed class OleDbServicesConverter : TypeConverter
603608
{
604609
private StandardValuesCollection? _standardValues;

src/libraries/System.Data.OleDb/src/OleDbDataAdapter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using System.ComponentModel;
55
using System.Data.Common;
66
using System.Diagnostics;
7+
using System.Diagnostics.CodeAnalysis;
78
using System.Runtime.InteropServices;
89

910
namespace System.Data.OleDb
1011
{
1112
[Designer("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterDesigner, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
1213
[ToolboxItem("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterToolboxItem, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
14+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
1315
public sealed class OleDbDataAdapter : DbDataAdapter, IDbDataAdapter, ICloneable
1416
{
1517
private static readonly object EventRowUpdated = new object();

src/libraries/System.Data.OleDb/src/OleDbDataReader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace System.Data.OleDb
1616
{
17+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
1718
public sealed class OleDbDataReader : DbDataReader
1819
{
1920
private readonly CommandBehavior _commandBehavior;

src/libraries/System.Data.OleDb/src/OleDbEnumerator.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Data.Common;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Globalization;
67

78
namespace System.Data.OleDb
@@ -12,6 +13,9 @@ public OleDbEnumerator()
1213
{
1314
}
1415

16+
#if NET
17+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
18+
#endif
1519
public DataTable GetElements()
1620
{
1721
DataTable dataTable = new DataTable("MSDAENUM");
@@ -21,17 +25,26 @@ public DataTable GetElements()
2125
return dataTable;
2226
}
2327

28+
#if NET
29+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
30+
#endif
2431
public static OleDbDataReader GetEnumerator(Type type)
2532
{
2633
return GetEnumeratorFromType(type);
2734
}
2835

36+
#if NET
37+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
38+
#endif
2939
internal static OleDbDataReader GetEnumeratorFromType(Type type)
3040
{
3141
object? value = Activator.CreateInstance(type, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, null, CultureInfo.InvariantCulture, null);
3242
return GetEnumeratorReader(value);
3343
}
3444

45+
#if NET
46+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
47+
#endif
3548
private static OleDbDataReader GetEnumeratorReader(object? value)
3649
{
3750
NativeMethods.ISourcesRowset? srcrowset;
@@ -66,6 +79,9 @@ private static OleDbDataReader GetEnumeratorReader(object? value)
6679
return dataReader;
6780
}
6881

82+
#if NET
83+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
84+
#endif
6985
public static OleDbDataReader GetRootEnumerator()
7086
{
7187
//readonly Guid CLSID_MSDAENUM = new Guid(0xc8b522d0,0x5cf3,0x11ce,0xad,0xe5,0x00,0xaa,0x00,0x44,0x77,0x3d);

src/libraries/System.Data.OleDb/src/OleDbFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Data.Common;
5+
using System.Diagnostics.CodeAnalysis;
56

67
namespace System.Data.OleDb
78
{
9+
[RequiresDynamicCode(OleDbConnection.TrimWarning)]
810
public sealed class OleDbFactory : DbProviderFactory
911
{
1012
public static readonly OleDbFactory Instance = new OleDbFactory();

0 commit comments

Comments
 (0)