Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

A DocumentDbContext whose class name does not end in "Context" gets no generated code and no diagnostic; its collections stay null

Closed Beginner friendly
#300 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

A pull request for this has already been merged.

  • #317 by @CaffeinatedCoder — merged

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp

Research direction

Start with IsPotentialDbContext in src/BLite.SourceGenerators/MapperGenerator.cs and the existing suffix convention in src/BLite.SourceGenerators/Helpers/BLiteConventions.cs. Verify how GetDbContextInfo performs the semantic inheritance check, then inspect the generator tests for coverage of DocumentDbContext subclasses without the Context suffix. Done means such a class produces the expected generated code, or a clearly specified diagnostic explains when it is skipped.

Written by the indexing model from the issue text.

Description

bug package/generator triage

The source generator only looks at classes whose name ends in Context. A DocumentDbContext subclass named anything else (Shop, AppDb, Store, CatalogDb) gets no generated code, and the build reports nothing. Its collection properties stay null, and the first call throws NullReferenceException, far from the cause.

The README used such a name itself until #298 (new AppDb(...) in the master-key and multi-process samples), which is how this was found.

Repro

public class Customer { public ObjectId Id { get; set; } public string Name { get; set; } = ""; }

public partial class ShopContext : DocumentDbContext
{
    public DocumentCollection<ObjectId, Customer> Customers { get; set; } = null!;
    public ShopContext(string path) : base(path) { }
}

public partial class Shop : DocumentDbContext     // same body, different name
{
    public DocumentCollection<ObjectId, Customer> Customers { get; set; } = null!;
    public Shop(string path) : base(path) { }
}

await using var ok = new ShopContext("a.db");   // ok.Customers is set
await using var db = new Shop("b.db");          // db.Customers is null
await db.Customers.InsertAsync(new Customer { Name = "Ada" });   // NullReferenceException

Build with -p:EmitCompilerGeneratedFiles=true: the generator emits GenCheck.ShopContext_Program.Mappers.g.cs and nothing for Shop; no BLITE diagnostic.

Expected: a class that derives from DocumentDbContext is generated whatever its name, or the build says why it is not.

Actual: silently skipped.

Where in the code (0450b97)

  • MapperGenerator.IsPotentialDbContext (src/BLite.SourceGenerators/MapperGenerator.cs:492-499) filters on classDecl.Identifier.Text.EndsWith(BLiteConventions.DbContextClassSuffix), with DbContextClassSuffix = "Context" (src/BLite.SourceGenerators/Helpers/BLiteConventions.cs:13). The filter has been there since the generator's first version (219efaa, v1.0.0).
  • GetDbContextInfo (MapperGenerator.cs:805-813) then checks semantically that the class inherits from DocumentDbContext, so the name filter is only a cheap pre-filter, and it drops real contexts.
  • Neither the README nor the XML docs of DocumentDbContext mention the naming rule.

Suggested fix

  • Drop the name condition from the syntax predicate (ClassDeclarationSyntax with a BaseList is cheap enough; the semantic check already decides), or
  • keep it as a fast path, and report a warning (BLITE00x) for any class that derives from DocumentDbContext but was skipped, naming the rule.
  • Test: a context named without the suffix is generated (or the diagnostic is reported), in the generator tests.

Related: #152 (contexts in the global namespace, the same kind of silent skip), #298.

Dominant language
C#
Stars
66
Forks
6
Avg merge
1d 2h
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EntglDb/BLite

All issues in EntglDb/BLite

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.