question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SqlClient UDT support needs an assembly-plugin model

See original GitHub issue

I built a .NET Standard implementation of the Microsoft.SqlServer.Types classes. This works great for insertion, but when deserializing I’ll get an exception like this: image

Instead I have to write something like:

var binvalue = reader.GetSqlBytes(rowid);
var g = SqlGeometry.Deserialize(binvalue);

This makes sense, because SqlClient has no idea I provided an implementation it could use. Assembly redirect only works for assemblies with the same name and public key, so that’s not really an option. How do we across all the different platforms allow us to use UDT in assemblies defined on each platform, and get the SqlClient to import the types?

The issue is somewhat called out in the doc:

SqlClient may fail to load a UDT in the event of mismatched UDT versions or other problems. (1)

A local copy of the UDT assembly must be available to the client project. (2)

The assembly loaded in SQL Server and the assembly on the client must be compatible in order for the UDT to be created on the client. For UDTs defined with the Native serialization format, the assemblies must be structurally compatible. For assemblies defined with the UserDefined format, the assembly must be available on the client. You do not need a copy of the UDT assembly on the client in order to retrieve the raw data from a UDT column in a table. (3)

In some situations, you may want to retrieve the raw data from the UDT column. Perhaps the type is not available locally (4)

Warning about client side usage of GEOMETRY, GEOGRAPHY and HIERARCHYID

A .NET Standard Implementation of the geometry types for reference which can be used as an example (just tweak unit tests to call GetValue instead of GetSqlBytes on the data reader): https://github.com/dotMorten/Microsoft.SqlServer.Types/blob/89c5e6158867d9603d93fde6286a0f32f01fa96d/src/Microsoft.SqlServer.Types.Tests/DBTests.cs#L81

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
divegacommented, May 14, 2019

@dotMorten I would vote for keeping this open. I am thinking about what you said in https://github.com/dotnet/SqlClient/issues/1#issuecomment-491994354, and I believe there is still an opportunity to enable plugging in your own types without having to hack with signing.

1reaction
bricelamcommented, Oct 16, 2018

Note this is different than the recent open source guidance around strong name keys. It’s a bit of magic for stealing an assembly’s identity without having its private key. This is why strong naming is not about security. 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft Sqlserver Types Version 10.0 0.0 - Colaboratory
Asp.Net - Application Cannot Load Microsoft.Sqlserver.Types . ... Sqlclient Udt Support Needs An Assembly-Plugin Model · Issue #79 ... SqlClient UDT support ...
Read more >
What query can I execute in SDK to force UDT to unmonitor ...
The UDT GUI has a view or two that seems to allow a person to select all monitored nodes, or all monitored ports,...
Read more >
Plugin error after updating the code
Hey! Fairley new to the assembly/plugin part, so I have a working assembly code on (on-premise) v9.0 that we needed to update a...
Read more >
System.Data.SqlClient.dll
Submit malware for free analysis with Falcon Sandbox and Hybrid Analysis technology. Hybrid Analysis develops and licenses analysis tools to fight malware.
Read more >
Coding User-Defined Types - SQL Server
This example shows how to implement a UDT to use in a SQL Server database. ... that your assembly requires in order to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found