Skip to content
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
2 changes: 1 addition & 1 deletion src/libraries/System.Data.OleDb/src/DbPropSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void SetLastErrorInfo(OleDbHResult lastErrorHr)
}
finally
{
UnsafeNativeMethods.ReleaseErrorInfoObject(errorInfo);
UnsafeNativeMethods.ReleaseComWrappersObject(errorInfo);
}
}

Expand Down
124 changes: 0 additions & 124 deletions src/libraries/System.Data.OleDb/src/OleDbComWrappers.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/libraries/System.Data.OleDb/src/OleDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ internal bool SupportSchemaRowset(Guid schema)
}
finally
{
UnsafeNativeMethods.ReleaseErrorInfoObject(errorInfo);
UnsafeNativeMethods.ReleaseComWrappersObject(errorInfo);
}
}
else if (0 < hresult)
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Data.OleDb/src/OleDbError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index)

if (OleDbHResult.DB_E_NOLOCALE == hr)
{
Marshal.ReleaseComObject(errorInfo);
UnsafeNativeMethods.ReleaseComWrappersObject(errorInfo);
lcid = Interop.Kernel32.GetUserDefaultLCID();
errorInfo = errorRecords.GetErrorInfo(index, lcid);

Expand All @@ -43,7 +43,7 @@ internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index)

if (OleDbHResult.DB_E_NOLOCALE == hr)
{
Marshal.ReleaseComObject(errorInfo);
UnsafeNativeMethods.ReleaseComWrappersObject(errorInfo);
lcid = Interop.Kernel32.GetUserDefaultLCID();
errorInfo = errorRecords.GetErrorInfo(index, lcid);

Expand All @@ -56,7 +56,7 @@ internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index)
{
this.source = ODB.FailedGetSource(hr);
}
Marshal.ReleaseComObject(errorInfo!);
UnsafeNativeMethods.ReleaseComWrappersObject(errorInfo);
}
}

Expand All @@ -66,7 +66,7 @@ internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index)
if (null != sqlErrorInfo)
{
this.nativeError = sqlErrorInfo.GetSQLInfo(out this.sqlState);
Marshal.ReleaseComObject(sqlErrorInfo);
UnsafeNativeMethods.ReleaseComWrappersObject(sqlErrorInfo);
}
}

Expand Down
54 changes: 19 additions & 35 deletions src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<NoWarn>$(NoWarn);CA2249</NoWarn>
<!-- Suppress SYSLIB0004: 'RuntimeHelpers.PrepareConstrainedRegions()' is obsolete to avoid ifdefs. -->
<NoWarn>$(NoWarn);SYSLIB0004</NoWarn>
<!-- Suppress CS3016: Arrays as attribute arguments is not CLS-compliant to work around https://github.com/dotnet/roslyn/issues/68526 in generated code -->
<NoWarn>$(NoWarn);CS3016</NoWarn>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
<PackageDescription>Provides a collection of classes for OLEDB.
Expand All @@ -32,36 +34,21 @@ System.Data.OleDb.OleDbTransaction</PackageDescription>
</PropertyGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetUserDefaultLCID.cs"
Link="Common\Interop\Windows\Kernel32\Interop.GetUserDefaultLCID.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetCurrentProcessId.cs"
Link="Common\Interop\Windows\Kernel32\Interop.GetCurrentProcessId.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.LocalAlloc.cs"
Link="Common\Interop\Windows\Kernel32\Interop.LocalAlloc.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.LocalFree.cs"
Link="Common\Interop\Windows\Kernel32\Interop.LocalFree.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.Semaphore.cs"
Link="Common\Interop\Windows\Kernel32\Interop.Semaphore.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WaitForSingleObject.cs"
Link="Common\Interop\Windows\Kernel32\Interop.WaitForSingleObject.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WaitForMultipleObjects.cs"
Link="Common\Interop\Windows\Kernel32\Interop.WaitForMultipleObjects.cs" />
<Compile Include="$(CommonPath)Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs"
Link="Common\Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs" />
<Compile Include="$(CommonPath)Interop\Windows\OleAut32\Interop.SetErrorInfo.cs"
Link="Common\Interop\Windows\OleAut32\Interop.SetErrorInfo.cs" />
<Compile Include="$(CommonPath)Interop\Windows\OleAut32\Interop.SysFreeString.cs"
Link="Common\Interop\Windows\OleAut32\Interop.SysFreeString.cs" />
<Compile Include="$(CommonPath)Interop\Windows\OleAut32\Interop.VariantClear.cs"
Link="Common\Interop\Windows\OleAut32\Interop.VariantClear.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs"
Link="Common\Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.PropVariantClear.cs"
Link="Common\Interop\Windows\Ole32\Interop.PropVariantClear.cs" />
<Compile Include="$(CommonPath)System\Data\Common\MultipartIdentifier.cs"
Link="Common\System\Data\Common\MultipartIdentifier.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs" Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetUserDefaultLCID.cs" Link="Common\Interop\Windows\Kernel32\Interop.GetUserDefaultLCID.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetCurrentProcessId.cs" Link="Common\Interop\Windows\Kernel32\Interop.GetCurrentProcessId.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.LocalAlloc.cs" Link="Common\Interop\Windows\Kernel32\Interop.LocalAlloc.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.LocalFree.cs" Link="Common\Interop\Windows\Kernel32\Interop.LocalFree.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.Semaphore.cs" Link="Common\Interop\Windows\Kernel32\Interop.Semaphore.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WaitForSingleObject.cs" Link="Common\Interop\Windows\Kernel32\Interop.WaitForSingleObject.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WaitForMultipleObjects.cs" Link="Common\Interop\Windows\Kernel32\Interop.WaitForMultipleObjects.cs" />
<Compile Include="$(CommonPath)Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs" Link="Common\Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs" />
<Compile Include="$(CommonPath)Interop\Windows\OleAut32\Interop.SetErrorInfo.cs" Link="Common\Interop\Windows\OleAut32\Interop.SetErrorInfo.cs" />
<Compile Include="$(CommonPath)Interop\Windows\OleAut32\Interop.SysFreeString.cs" Link="Common\Interop\Windows\OleAut32\Interop.SysFreeString.cs" />
<Compile Include="$(CommonPath)Interop\Windows\OleAut32\Interop.VariantClear.cs" Link="Common\Interop\Windows\OleAut32\Interop.VariantClear.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs" Link="Common\Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.PropVariantClear.cs" Link="Common\Interop\Windows\Ole32\Interop.PropVariantClear.cs" />
<Compile Include="$(CommonPath)System\Data\Common\MultipartIdentifier.cs" Link="Common\System\Data\Common\MultipartIdentifier.cs" />
<Compile Include="AdapterSwitches.cs" />
<Compile Include="ColumnBinding.cs" />
<Compile Include="DbBindings.cs" />
Expand Down Expand Up @@ -136,18 +123,15 @@ System.Data.OleDb.OleDbTransaction</PackageDescription>
<Compile Include="System\Data\ProviderBase\DbMetaDataFactory.cs" />
<Compile Include="System\Data\ProviderBase\DbReferenceCollection.cs" />
<Compile Include="System\Data\ProviderBase\WrappedIUnknown.cs" />
<Compile Include="$(CommonPath)System\Obsoletions.cs"
Link="Common\System\Obsoletions.cs" />
<Compile Include="$(CommonPath)System\Obsoletions.cs" Link="Common\System\Obsoletions.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
<Compile Include="UnsafeNativeMethods.COMWrappers.cs" />
<Compile Include="OleDbComWrappers.cs" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\System.Data.OleDb.OleDbMetaData.xml"
LogicalName="System.Data.OleDb.OleDbMetaData.xml" />
<EmbeddedResource Include="Resources\System.Data.OleDb.OleDbMetaData.xml" LogicalName="System.Data.OleDb.OleDbMetaData.xml" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Data.OleDb;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace System.Data.Common
{
Expand All @@ -15,27 +16,15 @@ internal static partial class UnsafeNativeMethods
[LibraryImport(Interop.Libraries.OleAut32)]
internal static unsafe partial OleDbHResult GetErrorInfo(
int dwReserved,
System.IntPtr* ppIErrorInfo);
[MarshalUsing(typeof(UniqueComInterfaceMarshaller<IErrorInfo>))]
out IErrorInfo? ppIErrorInfo);

internal static unsafe OleDbHResult GetErrorInfo(
int dwReserved,
out UnsafeNativeMethods.IErrorInfo? ppIErrorInfo)
internal static void ReleaseComWrappersObject(object? obj)
{
ppIErrorInfo = null;
IntPtr pErrorInfo;
var hr = GetErrorInfo(dwReserved, &pErrorInfo);
if (hr == OleDbHResult.S_OK)
if (obj is not null)
{
ppIErrorInfo = (UnsafeNativeMethods.IErrorInfo)OleDbComWrappers.Instance
.GetOrCreateObjectForComInstance(pErrorInfo, CreateObjectFlags.UniqueInstance);
((ComObject)obj).FinalRelease();
}

return hr;
}

internal static void ReleaseErrorInfoObject(UnsafeNativeMethods.IErrorInfo errorInfo)
{
((IDisposable)errorInfo).Dispose();
}
}
}
46 changes: 24 additions & 22 deletions src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Security;

#pragma warning disable 0618 // ComInterfaceType.InterfaceIsDual is obsolete
Expand Down Expand Up @@ -507,10 +508,18 @@ System.Data.OleDb.OleDbHResult GetSchemas(
[Out] out IntPtr prgRestrictionSupport);
}

[Guid("1CF2B120-547D-101B-8E65-08002B2BD119"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
internal interface IErrorInfo
[Guid("0C733A74-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GeneratedComInterface, SuppressUnmanagedCodeSecurity]
internal partial interface ISQLErrorInfo
{
[Obsolete("not used", true)] void GetGUID(/*deleted parameter signature*/);
[return: MarshalAs(UnmanagedType.I4)]
int GetSQLInfo(
[MarshalAs(UnmanagedType.BStr)] out string pbstrSQLState);
}

[Guid("1CF2B120-547D-101B-8E65-08002B2BD119"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GeneratedComInterface, SuppressUnmanagedCodeSecurity]
internal partial interface IErrorInfo
{
[Obsolete("not used")] void GetGUID(/*deleted parameter signature*/);

[PreserveSig]
System.Data.OleDb.OleDbHResult GetSource(
Expand Down Expand Up @@ -539,25 +548,26 @@ virtual HRESULT STDMETHODCALLTYPE GetHelpContext(
/* [out] */ DWORD *pdwHelpContext) = 0;
#endif

[Guid("0C733A67-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
internal interface IErrorRecords
[Guid("0C733A67-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GeneratedComInterface, SuppressUnmanagedCodeSecurity]
internal partial interface IErrorRecords
{
[Obsolete("not used", true)] void AddErrorRecord(/*deleted parameter signature*/);
[Obsolete("not used")] void AddErrorRecord(/*deleted parameter signature*/);

[Obsolete("not used", true)] void GetBasicErrorInfo(/*deleted parameter signature*/);
[Obsolete("not used")] void GetBasicErrorInfo(/*deleted parameter signature*/);

[PreserveSig]
System.Data.OleDb.OleDbHResult GetCustomErrorObject( // may return E_NOINTERFACE when asking for IID_ISQLErrorInfo
[In] int ulRecordNum,
[In] in Guid riid,
[Out, MarshalAs(UnmanagedType.Interface)] out ISQLErrorInfo ppObject);
int ulRecordNum,
in Guid riid,
[MarshalUsing(typeof(UniqueComInterfaceMarshaller<ISQLErrorInfo>))]
out ISQLErrorInfo ppObject);

[return: MarshalAs(UnmanagedType.Interface)]
[return: MarshalUsing(typeof(UniqueComInterfaceMarshaller<IErrorInfo>))]
IErrorInfo GetErrorInfo(
[In] int ulRecordNum,
[In] int lcid);
int ulRecordNum,
int lcid);

[Obsolete("not used", true)] void GetErrorParameters(/*deleted parameter signature*/);
[Obsolete("not used")] void GetErrorParameters(/*deleted parameter signature*/);

int GetRecordCount();
}
Expand Down Expand Up @@ -725,14 +735,6 @@ System.Data.OleDb.OleDbHResult GetReferencedRowset(
//int GetSpecification(/*deleted parameter signature*/);
}

[Guid("0C733A74-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
internal interface ISQLErrorInfo
{
[return: MarshalAs(UnmanagedType.I4)]
int GetSQLInfo(
[Out, MarshalAs(UnmanagedType.BStr)] out string pbstrSQLState);
}

[Guid("0C733A5F-2A1C-11CE-ADE5-00AA0044773D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport, SuppressUnmanagedCodeSecurity]
internal interface ITransactionLocal
{
Expand Down
Loading