I'm running into a problem when trying to use this library. Hopefully it's just something simple I'm overlooking.
As the simplest possible example, here is a .NET 5.0 console app:
SqlTest.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.90" />
<PackageReference Include="dotMorten.Microsoft.SqlServer.Types" Version="1.3.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.3" />
</ItemGroup>
</Project>
Program.cs
using System;
using Dapper;
using Microsoft.Data.SqlClient;
namespace SqlTest
{
class Program
{
static void Main(string[] args)
{
var conn = new SqlConnection("Server=localhost;Database=AdventureWorks;Trusted_Connection=True;");
var addresses = conn.Query("SELECT TOP 10 * FROM Person.Address");
foreach (var address in addresses)
{
Console.WriteLine(address);
}
conn.Dispose();
}
}
}
I'm querying AdventureWorks's Person.Address, since the SpatialLocation field in it is of type "geography". When trying this on a different table without geography (e.g. AddressType), the program runs without exception. The exception that I'm getting is:
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'. The system cannot find the file specified.
File name: 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.Data.SqlClient.SqlConnection.ResolveTypeAssembly(AssemblyName asmRef, Boolean throwOnError)
at Microsoft.Data.SqlClient.SqlConnection.<>c__DisplayClass179_0.b__0(AssemblyName asmRef)
at System.TypeNameParser.ResolveAssembly(String asmName, Func2 assemblyResolver, Boolean throwOnError, StackCrawlMark& stackMark) at System.TypeNameParser.ConstructType(Func
2 assemblyResolver, Func4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark) at System.TypeNameParser.GetType(String typeName, Func
2 assemblyResolver, Func4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark) at System.Type.GetType(String typeName, Func
2 assemblyResolver, Func4 typeResolver, Boolean throwOnError) at Microsoft.Data.SqlClient.SqlConnection.CheckGetExtendedUDTInfo(SqlMetaDataPriv metaData, Boolean fThrow) at Microsoft.Data.SqlClient.SqlDataReader.GetValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData metaData) at Microsoft.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i) at Microsoft.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at Dapper.SqlMapper.<>c__DisplayClass171_0.<GetDapperRowDeserializer>b__0(IDataReader r) in /_/Dapper/SqlMapper.cs:line 1877 at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in /_/Dapper/SqlMapper.cs:line 1102 at System.Collections.Generic.List
1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable1 commandTimeout, Nullable
1 commandType) in //Dapper/SqlMapper.cs:line 725
at Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable1 commandTimeout, Nullable
1 commandType) in //Dapper/SqlMapper.cs:line 652
at SqlTest.Program.Main(String[] args) in c:\zproj\SqlTest\SqlTest\Program.cs:line 13
c:\zproj\SqlTest\SqlTest\bin\Debug\net5.0\SqlTest.exe (process 4288) exited with code -532462766.
Press any key to close this window . . .
When I instead use System.Data.SqlClient and Microsoft.SqlServer.Types:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.90" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.1016.290" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
</ItemGroup>
</Project>
I do not get an exception. Instead, I get the warning:
Warning NU1701 Package 'Microsoft.SqlServer.Types 14.0.1016.290' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project. SqlTest c:\zproj\SqlTest\SqlTest\SqlTest.csproj 1
...which is what lead me to seek out this project in the first place. (Although it seems to work fine on Windows, despite the warning, it may be causing problems on Apple computers--I can't 100% verify this yet).
The error message seems to indicate that the file can't be found, but it does appear to be there in the bin folder. Am I configuring something wrong?