Hi @Moshe Yalovsky , Welcome to Microsoft Q&A,
Your problem may be caused by two different issues:
- File not found exception:
System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'. The system cannot find the file specified.
- The platform does not support exceptions:
System.PlatformNotSupportedException HResult=0x80131539 Message=Microsoft.Data.SqlClient is not supported on this platform.
To resolve these two issues, you can follow these steps:
Solve file not found exception
- In the Console application project, ensure that the
Microsoft.Data.SqlClient
package is installed correctly. You can check in your project files (*.csproj
) for the following:<ItemGroup> <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" /> </ItemGroup>
- Make sure that the
Microsoft.Data.SqlClient.dll
file is located in thebin
directory.
Solve the problem that the platform does not support the exception
- Make sure your application is running in 64-bit mode. You can check and change your project's target platform by following these steps:
- In Visual Studio, right-click the project and select Properties.
- Under the Build tab, make sure Target Platform is set to x64.
- Add the following properties to the project file (
*.csproj
) to specify the target platform:<PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <UseWPF>true</UseWPF> <!-- If your project uses WPF --> <Platforms>x64</Platforms> </PropertyGroup>
With the above steps, you should be able to resolve both exceptions. If the problem persists, please let me know and I will try my best to help you resolve it.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.