Comments (9)
@dotMorten do you have any materials where I could learn more about the bit patterns used in implementing HierarchyId?
Or maybe you have some ideas how to fix this issue?
from microsoft.sqlserver.types.
do you have any materials where I could learn more about the bit patterns used in implementing HierarchyId?
Nope. I didn't even provide this implementation (community contribution), and honestly don't even know what it is used for. Part of me wish I didn't accept the PR, because I have a really hard time maintaining that part of the source code, and really rely on the community to do this.
from microsoft.sqlserver.types.
@olmobrutall Would you be able to help with this issue? Or provide some materials where I could learn more about these bits patterns?
Definitely, serialization part is broken. When I try to look at data in SQL management studio I'm getting an exception
after using .ToString
on HierarchyId
A .NET Framework error occurred during execution of user-defined routine or aggregate "hierarchyid":
Microsoft.SqlServer.Types.HierarchyIdException: 24000: SqlHierarchyId operation failed because HierarchyId object was constructed from an invalid binary string.
Microsoft.SqlServer.Types.HierarchyIdException:
at Microsoft.SqlServer.Types.ex_raise(Int32 major, Int32 minor, Int32 sev, Int32 state, Object param1, Object param2, Object param3)
at Microsoft.SqlServer.Types.OrdPath.GetBits(UInt16 startBit, UInt16 nBits, UInt64& bits)
at Microsoft.SqlServer.Types.OrdPath.ExtractOrd(UInt16& bitOffset, UInt32 stage, Int64& ord)
at Microsoft.SqlServer.Types.OrdPath.ExtractComponent(UInt16& bitOffset, SComponent& component, levelType& type)
at Microsoft.SqlServer.Types.OrdPath.ToString()
from microsoft.sqlserver.types.
Hi @ppasieka,
the bit patterns come from http://www.adammil.net/blog/v100_how_the_SQL_Server_hierarchyid_data_type_works_kind_of_.html
Not sure if I’ll find time to work on it, but I can review a potential change if you go for it.
Cheers
from microsoft.sqlserver.types.
It's definitely an issue with serialization, I've converted the code to a Unit Test and also compare with values comming from the database:
[DataTestMethod]
[DataRow("/1.0.2/")]
[DataRow("/1.1.2/")]
[DataRow("/1.2.2/")]
[DataRow("/1.3.2/")]
[DataRow("/3.0/")]
public void SerializeDeserialize(string route)
{
var parsed = SqlHierarchyId.Parse(route);
//var ms = new MemoryStream();
//parsed.Write(new BinaryWriter(ms));
//ms.Position = 0;
//var roundTrip = new Microsoft.SqlServer.Types.SqlHierarchyId();
//roundTrip.Read(new BinaryReader(ms));
//Assert.AreEqual(parsed, roundTrip);
using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=HierarchyTest;Integrated Security=true"))
{
con.Open();
var id = new SqlCommand($"INSERT INTO [dbo].[TreeNode] (Route) output INSERTED.ID VALUES ('{route}') ", con).ExecuteScalar();
using (var reader = new SqlCommand($"SELECT Route FROM [dbo].[TreeNode] WHERE ID = " + id, con).ExecuteReader())
{
while (reader.Read())
{
var roundTrip = new Microsoft.SqlServer.Types.SqlHierarchyId();
roundTrip.Read(new BinaryReader(reader.GetStream(0)));
Assert.AreEqual(parsed, roundTrip);
}
}
}
The deserializer works, the serializer produces the error. Maybe tomorrow I can take a deeper look.
from microsoft.sqlserver.types.
@olmobrutall Thanks. I will also look into it tomorrow :) And yes I came to the same conclusion that the issue is with a serializer. Deserialization part work for me without any problems so far
from microsoft.sqlserver.types.
Fixed in #55
from microsoft.sqlserver.types.
@olmobrutall amazing 👍 I will check it against my project. Thanks for that fast response 😊
from microsoft.sqlserver.types.
@dotMorten Fix provided in #55 works nicely. What do you think about creating a release? With PRs #55 and #47 out, the list of HierarychId problems would be reduced to only one (#36)
from microsoft.sqlserver.types.
Related Issues (20)
- ToString() of SqlHierarchyId does not return "NULL" when IsNull == true HOT 1
- GetDescendant for a simple range fails with a HierarchyIdException HOT 2
- Throw HierarchyIdException instead of ArgumentException in GetDescendant method
- HierarchyId serialized in an invalid format which can't be deserialized HOT 11
- Some Geography cannot be deserialized. HOT 4
- When using Microsoft.Data.SqlClient an InvalidCastException will be thrown HOT 3
- Could not load file or assembly Microsoft.SqlServer.Types HOT 13
- SqlHierarchyId Write/Read roundtrip causes data corruption HOT 9
- System.Data.SqlClient needs a version bumb from 4.5.1 to 4.8.3 HOT 4
- assembly load error HOT 4
- DataReader.GetFieldType returned null HOT 10
- MultiPoint issue? HOT 2
- Specified type is not registered on the target. HOT 1
- Referenced assembly 'Microsoft.SqlServer.Types, Version=2.5.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name
- Fill DataTable throws DataReader.GetFieldType null
- Insert to SQL Server throws exception - `Specified type is not registered on the target server`. HOT 1
- Using Microsoft.Data.SqlClient 5.0.1 causes System.TypeLoadException: Could not load type 'Microsoft.Data.SqlClient.Server.IBinarySerialize' HOT 10
- Security Vulnerability: https://github.com/advisories/GHSA-8g2p-5pqh-5jmc HOT 7
- Upgrade from Framework to Standard HOT 2
- STIsValid returning incorrect result for parameterized query HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoft.sqlserver.types.