Skip to content

Conversation

@whitecostume
Copy link
Contributor

Because the default compare sorting rules of c# string are different from those of cpp, the binary file exported by flatc -b cannot use LookupByKey.
Modify the code generator to unify the rules

Because the default compare sorting rules of c# string are different from those of cpp, the binary file exported by flatc -b cannot use LookupByKey
@google-cla
Copy link

google-cla bot commented Mar 3, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@timestee
Copy link

timestee commented Sep 6, 2025

I ran into an issue with the generated C# code for __lookup_by_key.

The binary search uses obj_.Key.CompareTo(key), but this fails to find elements even though the vector is correctly sorted. When I replace it with string.Compare(obj_.Key, key, StringComparison.Ordinal), the lookup works as expected.

I'm new to FlatBuffers, but I feel that reliable key lookups should be a fundamental requirement. Why is CompareTo used here instead of string.Compare(..., StringComparison.Ordinal)? Is this intended behavior or a bug in the C# code generator?

@jtdavis777 jtdavis777 linked an issue Dec 1, 2025 that may be closed by this pull request
@jtdavis777
Copy link
Collaborator

I would love to see a regression test for this but happy to merge as is

@jtdavis777 jtdavis777 merged commit 97d26ab into google:master Dec 1, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c# c++ codegen Involving generating code from schema

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fixed sortvector issue with string as key in C#

3 participants