Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HierarchyId serialized in an invalid format which can't be deserialized #49

Closed
AndyBates6668 opened this issue Oct 3, 2020 · 11 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@AndyBates6668
Copy link

Hi,

We've been using this great class for our project and it's saved us a lot of time.

We seem to have found a problem serialising it to a SQL column. We have two values that have been written which fail to deserialize both in the HierarchyId and real HierarchyId (in SQL server and the help class).

The exception thrown by the each of the HierarchyId is when attempting to deserialize is:

$exception | {"No pattern found for: 0000010110000"} | System.InvalidCastException
"No pattern found for: 000001011010110000000"

We're investigating what the hierarchy identifiers were which generated these values but all we currently have is the hierarchy identifier binary information which is: 0x61D500B0 and 0x61D500B580. We'd expect the string value to be something like '/1.-6/-2' or '/1.-6/0/' which does appear to generate the correct binary data and works with both HierarchyId and the real HierarchyId.

I'll update this thread as I find more information. The problem was created by the test team so I'm afraid I don't have much to go on at present.

Thanks

  • Andy
@dotMorten dotMorten added bug Something isn't working help wanted Extra attention is needed labels Oct 3, 2020
@dotMorten
Copy link
Owner

A small testmethod the shows the problem would be awesome. If you clone the repo and add it to the test class, the test should pass for .net framework (as that runs against official libraries) and fail against .net core.

@AndyBates6668
Copy link
Author

As I say I'm not sure what the string was that generated that binary data. The HierarchyId class obviously generated it but it fails to deserialize in both .net framework and the .net core builds. I'm doing some more digging so will report what I turn up. Is it possible to decode the binary data or at least identify what the hierarchy id is (or even part of it)?

@dotMorten
Copy link
Owner

In that case we need to find what id got serialized and validate that they can deserialize again.

TBH I don't know anything about these ids. It was a community contribution and has been maintained by external devs so the more info you can find the greater chance it can get resolved

@AndyBates6668
Copy link
Author

As I say we're using the library and the test team caused invalid serialised hierarchy identifiers to be generated and dropped into the SQL database. I'll see if I can reproduce and get the source identifiers for these or do some more digging to see how they were generated.

@ppasieka
Copy link
Contributor

@AndyBates6668 fix for this issue is in #55

@AndyBates6668
Copy link
Author

There are 2 fixes I'm interested in seeing released. This plus the GetDescendants issue. Do we know when a pre-release/release can be completed for further testing? Thanks Andy

@Torvin
Copy link

Torvin commented Oct 28, 2020

Here's a test that passes for full framework and fails in .net core:

public void TestWrongSerialization()
{
    var h = SqlHierarchyId.Parse("/3.1/");
    var ms = new MemoryStream();
    h.Write(new BinaryWriter(ms));
    var value = ms.ToArray();
    CollectionAssert.AreEqual(value, new byte[] { 0x81, 0x60 });
}

Looks like it's fixed in #55

@AndyBates6668
Copy link
Author

What is the process for the PRs for resolving issues 46 and this issue to be completed? We're using the code and seeing this issue more frequently so would like to get the fixes in place. Many thanks Andy

@dotMorten
Copy link
Owner

The process is to download the source code and build it yourself - at least until I don't feel burnt out and again have the energy to dig into these PRs, test them, and release a new version.

@Torvin
Copy link

Torvin commented Nov 9, 2020

@dotMorten thank you for your hard work. If it helps, I did exactly that - downloaded the code from PR #55 branch and using it in production right now and everything is working fine so far

@dotMorten
Copy link
Owner

Try v1.3.0 that have the #55 code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants