-
Type:
Bug
-
Resolution: Won't Do
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: LINQ
-
None
-
(copied to CRM)
-
None
-
Dotnet Drivers
-
None
-
None
-
None
-
None
-
None
-
None
In versions 2.26.0 to 3.1.0, the .NET/C# drivers throws a System.FormatException
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace TestApp {
class Program {
static async Task Main(string[] args) {
string connectionString = "<connection_string>";
string databaseName = "entity";
string collectionName = "entity-folders";
var client = new MongoClient(connectionString);
Console.WriteLine("connected");
var db = client.GetDatabase(databaseName);
var collection = db.GetCollection < FolderEntity > (collectionName);
try {
var query = collection.AsQueryable()
.Where(x => x.Name.Equals("prefix" + x.Id.ToString())); var res = await query.ToListAsync();
Console.WriteLine($"Success: {res.Count}");
}
catch (Exception ex) {
Console.WriteLine($"Error: {ex.Message}");
}
}
}
public record FolderEntity {
[BsonId, BsonRepresentation(BsonType.ObjectId)]
public required string Id {get; set;}
public required string Name {get; set;}
}
}
"Error: 'prefix' is not a valid 24 digit hex string."
The same is not the case for v3.2.0+ or even v2.25.0. The query succeeds with those versions. The behavior is the same irrespective of whether a POCO is used or a record.