You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A DocumentDbContext whose class name does not end in "Context" gets no generated code and no diagnostic; its collections stay null #300
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
publicclassCustomer{publicObjectIdId{get;set;}publicstringName{get;set;}="";}publicpartialclassShopContext:DocumentDbContext{publicDocumentCollection<ObjectId,Customer>Customers{get;set;}=null!;publicShopContext(stringpath):base(path){}}publicpartialclassShop:DocumentDbContext// same body, different name{publicDocumentCollection<ObjectId,Customer>Customers{get;set;}=null!;publicShop(stringpath):base(path){}}awaitusingvarok=newShopContext("a.db");// ok.Customers is setawaitusingvardb=newShop("b.db");// db.Customers is nullawaitdb.Customers.InsertAsync(newCustomer{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.
Activity
mrdevrobot commentedon Oct 18, 2026
Reproduced on 0450b97: a context named
Shopbuilds with no diagnostic and its collections are null. Medium.fix(generator): discover a DocumentDbContext whatever its class name (#…