-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
First round of converting System.Data.OleDb to COMWrappers #54822
Conversation
This change just remove warning from ILLink and do not make attempt to convert other COM object creation to use ComWrappers Also I have to add target net5.0-windows where ComWrappers would be used. Same concerns regarding testing as in dotnet#54636 Two calls inside OleDbDataAdapter call GetErrorInfo but do not do anything with results. That's probably mistake from previous refactoring. These parts does not touched and left as is. Need advice on that specific parts how to proceed.
Tagging subscribers to this area: @roji, @ajcvickers Issue DetailsThis change just remove warning from ILLink and do not make attempt Also I have to add target net5.0-windows where ComWrappers would be Two calls inside OleDbDataAdapter call GetErrorInfo but do not do anything with results. That's probably mistake from previous refactoring. These parts does not touched and left as is. Need advice on that specific parts how to proceed.
|
src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.COMWrappers.cs
Outdated
Show resolved
Hide resolved
[DllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode, PreserveSig = true)] | ||
internal static extern System.Data.OleDb.OleDbHResult GetErrorInfo( | ||
[In] int dwReserved, | ||
[Out] out System.IntPtr ppIErrorInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use out
in P/Invokes, but instead use pointers. This matches the native signatures as close as possible, and allows for the native marshalling to do less work. In this case, the native marshalling needs to pin the managed reference out IntPtr ppIErrorInfo
. But it doesn't if the signature is a pointer.
[Out] out System.IntPtr ppIErrorInfo); | |
[Out] System.IntPtr* ppIErrorInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also drop the [Out]
attribute.
src/libraries/System.Data.OleDb/src/OleDbException.NoCOMWrappers.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Data.OleDb/src/OleDbException.COMWrappers.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Data.OleDb/src/OleDbDataAdapter.COMWrappers.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
<Compile Include="OleDbConnection.COMWrappers.cs" /> | ||
<Compile Include="OleDbException.COMWrappers.cs" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? Don't you want the !
of the above condition on line 102?
Or maybe even just not on TargetFramework net5.0 compatible, but still on Windows:
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0')) and '$(TargetsWindows)' == 'true'">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would include net461-windows which is wrong as that's facade assembly. The condition is probably missing a '$(TargetsWindows)' == 'true'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I would use
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0')) and'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'">
to be symmetrical with the first ItemGroup condition above.
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ViktorHofer and @eerhardt I made changes, but I'm not sure if this is proper way. All I can say, not it does not fails during build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. My only comments would be to make the ItemGroup conditions in the same order, to help with readability:
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'">
...
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', $(NetCoreAppCurrent))) and '$(TargetsWindows)' == 'true'">
...
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', $(NetCoreAppCurrent))) and '$(TargetsWindows)' == 'true'">
would become
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'">
...
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', $(NetCoreAppCurrent)))">
...
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true' and !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', $(NetCoreAppCurrent)))">
And then change the IsTargetFrameworkCompatible
to use net5.0
, since COMWrappers were introduced in net5.0
. This helps with maintainability in the long term, when we update NetCoreAppCurrent
to be net7.0
in the future.
{ | ||
internal static partial class ODB | ||
{ | ||
internal static OleDbHResult GetErrorDescription(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult hresult, out string message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code here between COMWrappers and NoCOMWrappers looks duplicated. Can it be folded back together?
|
||
public sealed partial class OleDbConnection | ||
{ | ||
internal static Exception? ProcessResults(OleDbHResult hresult, OleDbConnection? connection, object? src) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we share the bulk of this code, and only pull out the differences into COMWrappers
vs. NoCOMWrappers
files? i.e. create new private methods on the partial classes.
@@ -11,7 +11,7 @@ | |||
|
|||
namespace System.Data.OleDb | |||
{ | |||
public sealed class OleDbException : System.Data.Common.DbException | |||
public sealed partial class OleDbException : System.Data.Common.DbException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be partial? I don't see the other side of the partial class.
@@ -70,13 +70,8 @@ internal static OleDbException CreateException(UnsafeNativeMethods.IErrorInfo er | |||
string? message = null; | |||
string? source = null; | |||
OleDbHResult hr = 0; | |||
|
|||
if (null != errorInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we need a null check here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There discussion about that #54822 (comment)
|
||
namespace System.Data.OleDb | ||
{ | ||
using SysTx = Transactions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this using used?
@eerhardt can you take a look? Also do I need to pursue creation of fake OleDbProvider to test for error condition which you notice? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good. I just had a few final comments. After these are addressed, I won't have anymore concerns. Would also be good to get @AaronRobinsonMSFT to sign off.
return e; | ||
} | ||
|
||
internal void OnInfoMessage(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a difference in the code of OnInfoMessage
between the COMWrappers file and the NoCOMWrappers file. Why do we need them split?
src/libraries/System.Data.OleDb/src/OleDbConnection.COMWrappers.cs
Outdated
Show resolved
Hide resolved
OleDbHResult hr = UnsafeNativeMethods.GetErrorInfo(0, &pErrorInfo); // 0 - IErrorInfo exists, 1 - no IErrorInfo | ||
if ((OleDbHResult.S_OK == hr) && (IntPtr.Zero != pErrorInfo)) | ||
{ | ||
UnsafeNativeMethods.IErrorInfo errorInfo = (UnsafeNativeMethods.IErrorInfo)OleDbComWrappers.Instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just split this line out into separate partial methods between the two? That way we don't need to duplicate this whole method?
…s.cs Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
[In] int dwReserved, | ||
[Out, MarshalAs(UnmanagedType.Interface)] out UnsafeNativeMethods.IErrorInfo? ppIErrorInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[In] int dwReserved, | |
[Out, MarshalAs(UnmanagedType.Interface)] out UnsafeNativeMethods.IErrorInfo? ppIErrorInfo); | |
int dwReserved, | |
[MarshalAs(UnmanagedType.Interface)] out UnsafeNativeMethods.IErrorInfo? ppIErrorInfo); |
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. Thanks for the contribution here, @kant2002! I like how this change cleaned up, and really didn't need that much changes in the end.
Yeah, @eerhardt your proposal to consolidate files was excellent. I remove 4 not needed files and that was great. |
@lewing @radical - is this a known issue? I can't see how this change could have caused this failure in the browser wasm staging leg.
|
This failed because emsdk could not be activated:
@radekdoulik the |
It must have been a network issue. I ran it for the 3rd time, and it looks like it is further than it was before. I'll merge this once that leg goes green. |
This change just remove warning from ILLink and do not make attempt
to convert other COM object creation to use ComWrappers
Also I have to add target net5.0-windows where ComWrappers would be
used. Same concerns regarding testing as in
#54636
Two calls inside OleDbDataAdapter call GetErrorInfo but do not do anything with results. That's probably mistake from previous refactoring. These parts does not touched and left as is. Need advice on that specific parts how to proceed.