SNI.dll not found, in the wrong directory
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
I have an Azure Functions project (1.0.37) that consumes other projects in my solution and some of them use Entity Framework Core 3 (3.1.6). This requires Microsoft.Data.SqlClient which has a dependency on Microsoft.Data.SqlClient.sni (SNI.dll).
SNI.dll is present under `$(TargetDir)\` (e.g. `D:\MyProject\Debug\net48\x86\SNI.dll`). However, when I run my code it hits the following exception when it tries to run some EFCore3 code that requires SNI:
`Microsoft.Data.SqlClient: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception. Microsoft.Data.SqlClient: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception. Microsoft.Data.SqlClient: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. Microsoft.Data.SqlClient: Failed to load \bin\Debug\net48\bin\x86\SNI.dll.`
According to this message, the runtime is looking for SNI.dll under `net48\bin\x86` rather than under `net48\x86` where it *actually* resides. The path `net48\bin\x86` does not exist.
I am able to resolve this locally by adding the following post-build event to my .csproj:
``
``
``
Note that I've tried copying SNI.dll to `net48\bin` but the runtime doesn't find it there (which I don't completely understand since that's where the bulk of the dependencies are).
Unfortunately, I am having issues when it comes time to "officially" build and publish the project. SNI.dll is not being copied to the correct location (`net48\bin\x86`) in the resulting `.zip` file. The project is being built in an ADO pipeline using the [Visual Studio Build task](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/visual-studio-build?view=azure-devops).
After examining the logs from the build task, it seemed like copying the file near the beginning of the "Publish" stage would solve the issue. Thus, I added the following to my .csproj:
``
``
``
I then ran the build pipeline again and verified the file was copied after the "_GenerateFunctionsAndCopyContentFiles" stage. However, it still was not added to the `.zip` file.
At this point I think I need to add a separate task to the pipeline that runs after the build task and adds SNI.dll to the correct location within the `.zip` file.
It's not a very elegant solution so I'm hoping I'm just missing something simple here. I feel like there has to be a better way to address this issue. Any help or insights would be appreciated.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.