Compilation errors while linking corefx\src\Common\src\Interop\Windows\NtDll\Interop.NtCreateFile.cs
I am getting the following compilation errors when linking Interop.NtCreateFile.cs in System.Data.SqlClient project.
FileSystemEnumerator.Win32.cs includes a call to Interop.NtDll.CreateFile method and no compilation issues are observer with this project.
Could someone kindly help me with the following:
- Are issues 1,2,3 and 5 are being resolved in the correct manner, if not is there a better solution ?
- How can I resolve Issue 4 (CS0029) ? I have added my comments and an excerpt from the log below, the logs are after including the mentioned changes.
| No | Error Code | Description | Project | File | Comments |
|---|---|---|---|---|---|
| 1. | CS0208 | Cannot take the address of, get the size of, or declare a pointer to a managed type ('Interop.UNICODE_STRING') | System.Data.SqlClient | Interop.NtCreateFile.cs | Removing the * operator resolves the compilation error. |
| 2. | CS0208 | Cannot take the address of, get the size of, or declare a pointer to a managed type ('Interop.UNICODE_STRING') | System.Data.SqlClient | Interop.NtCreateFile.cs | Removing the * operator resolves the compilation error. |
| 3. | BCL0015 | ntdll.dll!NtCreateFile is not supported on one\more targeted platforms. | System.Data.SqlClient | Interop.NtCreateFile.cs | This error can be removed by suppressing the warning #pragma warning disable BCL0015 // Invalid Pinvoke call. Is there a better way to do this ? |
| 4. | CS0029 | Cannot implicitly convert type 'System.IntPtr' to 'string' | System.Data.SqlClient | Interop.NtCreateFile.cs | Changing this to Buffer = new string( c ) resolves the intellisense error, however the compilation error convert type 'string' to 'System.IntPtr' is observed. |
| 5. | CS0208 | Cannot take the address of, get the size of, or declare a pointer to a managed type ('Interop.UNICODE_STRING') | System.Data.SqlClient | Interop.NtCreateFile.cs | Removing the & operator resolves the compilation error. |
System.Linq.Expressions -> D:\dotNetCore\corefx\bin\Windows_NT.AnyCPU.Debug\System.Linq.Expressions\netcoreapp\System
.Linq.Expressions.dll
System.Private.Xml.Linq -> D:\dotNetCore\corefx\bin\Windows_NT.AnyCPU.Debug\System.Private.Xml.Linq\netcoreapp\System
.Private.Xml.Linq.dll
System.Xml.XmlDocument -> D:\dotNetCore\corefx\bin\Windows_NT.AnyCPU.Debug\System.Xml.XmlDocument\netcoreapp\System.X
ml.XmlDocument.dll
System.Xml.XPath -> D:\dotNetCore\corefx\bin\Windows_NT.AnyCPU.Debug\System.Xml.XPath\netcoreapp\System.Xml.XPath.dll
System.Xml.ReaderWriter -> D:\dotNetCore\corefx\bin\Windows_NT.AnyCPU.Debug\System.Xml.ReaderWriter\netcoreapp\System
.Xml.ReaderWriter.dll
System.Xml.XmlSerializer -> D:\dotNetCore\corefx\bin\Windows_NT.AnyCPU.Debug\System.Xml.XmlSerializer\netcoreapp\Syst
em.Xml.XmlSerializer.dll
System.Xml.XPath.XDocument -> D:\dotNetCore\corefx\bin\Windows_NT.AnyCPU.Debug\System.Xml.XPath.XDocument\netcoreapp\
System.Xml.XPath.XDocument.dll
System.Xml.XDocument -> D:\dotNetCore\corefx\bin\Windows_NT.AnyCPU.Debug\System.Xml.XDocument\netcoreapp\System.Xml.X
Document.dll
Build FAILED.
D:\dotNetCore\corefx\src\Common\src\Interop\Windows\NtDll\Interop.NtCreateFile.cs(46,30): error CS0029: Cannot implicit
ly convert type 'string' to 'System.IntPtr' [D:\dotNetCore\corefx\src\System.IO.FileSystem\src\System.IO.FileSystem.csp
roj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:02:26.71
Command execution failed with exit code 1.
cc @saurabh500 @AfsanehR
corefx has two conflicting definitions of UNICODE_STRING:
\corefx\src\Common\src\Interop\Windows\Interop.UNICODE_STRING.cs
\corefx\src\Common\src\Interop\Windows\sspicli\Interop.UNICODE_STRING.cs
Interop.NtCreateFile.cs assumes the first one, but your System.Data.SqlClient includes the second one.
Thank you @jkotas for the prompt response, changing the include file to \corefx\src\Common\src\Interop\Windows\Interop.UNICODE_STRING.cs resolved issues 1,2,4 and 5.
Is there a better way you can suggest to suppress issue/warning BCL0015 ?
What are you using NtCreateFile for?
cc @JeremyKuhne
@jkotas
I am trying to add SqlFileStream capability to System.Data.SqlClient in .Net Core dotnet/SqlClient#15
Here is the .Net Framework implementation that I am trying to port over.
I assume that you are calling NtCreateFile in netcoreapp Windows configuration only. I am not sure why you are getting the warning in the first place. System.IO.FileSystem is calling NtCreateFile too and I am not able to find any code to suppress the warning around it. @JeremyKuhne Have you done anything special for it?
Suppressing the warning sounds reasonable to me to allow you to make progress.
@keeratsingh was this sufficient?
@JeremyKuhne Have you done anything special for it?
No, other than I only used it in netcoreapp. From a first look at the code I don't see why this is using NTCreateFile rather than CreateFile (non UAP)/CreateFile2 (UAP). I used it only in the non UWP builds to open handles relative to another handle (perf optimization). The code here isn't doing that.
@keeratsingh If you can't switch to CreateFile/CreateFile2 you won't be able to enable this class in UAP- it is blocked. If you run into issues trying to change let me know and I'll do what I can to help.
@jkotas Yes, so far this would be windows specific only, given that it requires the transaction context token as described below, I have suppressed the warning.
@danmosemsft Yes this resolved the initial compilations errors.
@JeremyKuhne For SqlFileStream to work we need acquire and supply two pieces of information:
- Path to the destination file: This can be acquired using PathName method, bear in mind this is not a UNC path to the physical file system on the server. The path is just a bogus path that has meaning only in the context of this transaction which SQL Server can use to map to the real file in the file system.
- Transaction Context Token: Secondly, we need a token that identifies the NTFS file system transaction that SQL Server initiated behind the scenes, which we obtain with the
GET_FILESTREAM_TRANSACTION_CONTEXTfunction.
This transaction context can be supplied via the Extended Attribute Buffer (eaBuffer) argument in case of NTCreateFile. I couldn't find a way to do the same with CreateFile/CreateFile2, hence why I used NTCreateFile. If there is way to do the same with CreateFile/CreateFile2 it would be more preferrable.
Also, the windows only compilation works fine without issues, however when I try to compile with flag -allconfigurations, I see the following errors. Any suggestions on resolving these ?
System.Threading.Tasks.Extensions -> D:\dotNetCore\corefx\bin\AnyOS.AnyCPU.Debug\System.Threading.Tasks.Extensions\netstandard\System.Threading.Tasks.Extensions.dll
System.Runtime.CompilerServices.Unsafe -> D:\dotNetCore\corefx\bin\AnyOS.AnyCPU.Debug\System.Runtime.CompilerServices.Unsafe\netstandard\System.Runtime.CompilerServices.Unsafe.dll
Build FAILED.
D:\dotNetCore\corefx\src\Common\src\Interop\Windows\NtDll\Interop.NtCreateFile.cs(29,13): error CS0246: The type or namespace name 'ReadOnlySpan<>' could not be found (are you missing a using directive or an assembly reference?) [D:\dotNetCore\corefx\src\System.Data.SqlClient\src\System.Data.SqlClient.csproj]
D:\dotNetCore\corefx\src\Common\src\Interop\Windows\NtDll\Interop.NtCreateFile.cs(14,20): error CS0103: The name 'Libraries' does not exist in the current context [D:\dotNetCore\corefx\src\System.Data.SqlClient\src\System.Data.SqlClient.csproj]
D:\dotNetCore\corefx\src\Common\src\Interop\Windows\NtDll\Interop.RtlNtStatusToDosError.cs(14,20): error CS0103: The name 'Libraries' does not exist in the current context [D:\dotNetCore\corefx\src\System.Data.SqlClient\src\System.Data.SqlClient.csproj]
D:\dotNetCore\corefx\src\Common\src\Interop\Windows\kernel32\Interop.GetFileType_SafeHandle.cs(11,20): error CS0103: The name 'Libraries' does not exist in the current context [D:\dotNetCore\corefx\src\System.Data.SqlClient\src\System.Data.SqlClient.csproj]
D:\dotNetCore\corefx\src\Common\src\Interop\Windows\kernel32\Interop.SetThreadErrorMode.cs(11,20): error CS0103: The name 'Libraries' does not exist in the current context [D:\dotNetCore\corefx\src\System.Data.SqlClient\src\System.Data.SqlClient.csproj]
Here are what the additions in the SqlClient csproj file look like.
<ItemGroup Condition="('$(TargetGroup)' == 'netstandard' OR '$(TargetGroup)' == 'netcoreapp') " >
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Errors.cs">
<Link>Common\Interop\Windows\Interop.Errors.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\NtDll\Interop.NtCreateFile.cs">
<Link>Common\Interop\Windows\NtDll\Interop.NtCreateFile.cs</Link>
</Compile>
.
.
.
</ItemGroup>
@JeremyKuhne I was able to resolve the compilation errors by editing the csproj file and adding different implementations for non-windows platforms. So the only questions left now is if there is a way to supply the Extended Attributes via CreateFile/CreateFile2.
So the only questions left now is if there is a way to supply the Extended Attributes via CreateFile/CreateFile2.
I think we're stuck with creating a .win32.cs and .winrt.cs for this for now. I'm not seeing options that are blessed by UWP. We can create an issue to track finding another way through.
Created issue dotnet/corefx#29379 to track finding another way as suggested. Closing this as the original issue was resolved.
.winrt.cs
It should be .Uap.cs. This is not WinRT specific.