Comments (9)
Could you share an example that demonstrates this problem?
from microsoft.sqlserver.types.
Here's a very simple case:
using Microsoft.SqlServer.Types;
using System;
using System.IO;
namespace SqlHierarchy.Repro
{
internal class Program
{
static void Main(string[] args)
{
var stream = new MemoryStream();
var writer = new BinaryWriter(stream, System.Text.Encoding.UTF8, true);
var hierarchy = SqlHierarchyId.Parse(new System.Data.SqlTypes.SqlString("/1/"));
Console.WriteLine(hierarchy);
hierarchy.Write(writer);
for (int i = 0; i < 10; i++)
{
writer.Write(i);
}
writer.Close();
stream.Position = 0;
var reader = new BinaryReader(stream);
hierarchy = new SqlHierarchyId();
hierarchy.Read(reader);
Console.WriteLine(hierarchy);
}
}
}
Expected: This should print /1/
twice.
Observed: Prints /1/
once, then crashes with:
Microsoft.SqlServer.Types.HierarchyIdException: '24000: SqlHierarchyId operation failed because HierarchyId object was constructed from an invalid binary string. '
from microsoft.sqlserver.types.
@masonwheeler Thanks this is awesome. I tried this with the official .NET Framework implementation and it gives a very similar exception, so from what I can tell, this is "as designed".
Only thing I can think of doing here is slightly tweaking the error message to match.
Unit test used to compare behavior:
[TestMethod]
[WorkItem(64)]
public void ReadFromContinuousStream()
{
var stream = new MemoryStream();
var writer = new BinaryWriter(stream, System.Text.Encoding.UTF8, true);
var hierarchy = SqlHierarchyId.Parse(new System.Data.SqlTypes.SqlString("/1/"));
hierarchy.Write(writer);
//Add extra bytes after
for (int i = 0; i < 10; i++)
{
writer.Write(i);
}
writer.Close();
stream.Position = 0;
var reader = new BinaryReader(stream);
var hierarchy2 = new SqlHierarchyId();
hierarchy2.Read(reader);
Assert.AreEqual(hierarchy.ToString(), hierarchy2.ToString());
}
from microsoft.sqlserver.types.
Error message thrown now matches .NET Framework implementation
from microsoft.sqlserver.types.
So where would I find the official repo to report this? It may be "as designed" but the design is completely broken.
from microsoft.sqlserver.types.
If you clone this repo and run the unit test, it'll repeat the tests for both this implementation as well as the official Microsoft .NET Framework implementation. AFAIK there is no official repo for that library, so I'm not sure where to report it. Having said that, I don't really see how this can be supported, since there doesn't appear to be any indicator in a binary stream that you've reached the end of a hierarchy object and should stop reading.
from microsoft.sqlserver.types.
Yeah, that's the entire point of my complaint, as I noted in the original post. This is inconsistent with the binary serialization format of the other types, which are length-prefixed. That's how you fix it: change the serialization format to something sane.
from microsoft.sqlserver.types.
You can try and get the sql server team to change a well-established format. I wish you the best of luck :-p
This is inconsistent with the binary serialization format of the other types
They are very different and serve different purposes, and AFAIK implemented by different teams.
from microsoft.sqlserver.types.
Perhaps when you write it, add \0
after each hierarchy and when reading it back in, use that as delimiter before feeding it into the reader? Would be simple to do to address your scenario.
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
- 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.