Linq2CouchBase: NullReferenceException in BeerSample


I’m trying to evaluate linq2CouchBase for a new project.
I got NiQL query working but the linq query doesn’t
Any advice on trouble-shooting would be greatly appreciated!


Here’s the call stack:

System.NullReferenceException: Object reference not set to an instance of an object.
at Couchbase.Linq.Execution.BucketQueryExecutor.ExecuteCollection(QueryModel queryModel, Boolean selectDocumentMetadata, ScalarResultBehavior& scalarResultBehavior)
at Couchbase.Linq.Execution.BucketQueryExecutor.ExecuteCollection[T](QueryModel queryModel)
at Couchbase.Linq.Execution.BucketQueryExecutor.ExecuteSingle[T](QueryModel queryModel, Boolean returnDefaultWhenEmpty)
at Remotion.Linq.Clauses.StreamedData.StreamedSingleValueInfo.ExecuteSingleQueryModel[T](QueryModel queryModel, IQueryExecutor executor)
at Remotion.Linq.Clauses.StreamedData.StreamedSingleValueInfo.ExecuteQueryModel(QueryModel queryModel, IQueryExecutor executor)
at Remotion.Linq.QueryModel.Execute(IQueryExecutor executor)
at Remotion.Linq.QueryProviderBase.Execute(Expression expression)
at Remotion.Linq.QueryProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.First[TSource](IQueryable`1 source)

Here’s the test code:
[TestMethod] //this works
public void TestNiql()
var bucket = GetBucket();
var beer = bucket.Query(@“SELECT * FROM beer-sample WHERE type=”“brewery”" LIMIT 1;");



public void TestLinq()
var bucket = GetBucket();
var db = new BeerSample(bucket);
var beer = db.Beers.First();

Hi @michael1,

I’m assuming that this is the same question posted twice? (See: Linq2CouchBase: NullReferenceException in beer sample test)

So I’ll try to help in this thread and ignore the other one.

Could you please post the code for your BeerSample class?


It appears that you’ve extended BucketContext as BeerSample. Can you provide the code you used there for the Beers property? Also, the code for your Beer POCO could be useful as well.


@btburnett3 -

Its probably from here: