Skip to content

Instantly share code, notes, and snippets.

@j2jensen
Created October 25, 2010 19:07
Show Gist options
  • Save j2jensen/645518 to your computer and use it in GitHub Desktop.
Save j2jensen/645518 to your computer and use it in GitHub Desktop.
The following unit test causes a null reference exception intermittently.
[TestMethod]
public void AllRepositoriesShouldBeCreatableViaDependencyInjection()
{
// By doing this in parallel, we simultaneously test whether our
// DI stuff can handle lots of multi-threaded requests.
var repositoryTypes = from a in CoreAssemblies.AsParallel()
from t in a.GetTypes()
where t.Name.EndsWith("Repository")
// Don't bother if they've been flagged as factory-built
where !t.GetCustomAttributes(typeof (FactoryBuiltAttribute), false).Any()
select t;
repositoryTypes.ForAll(repositoryType =>
{
var repository = _kernel.Get(repositoryType);
});
}
Test method Modus.Tests.Modules.ModuleTest.AllRepositoriesShouldBeCreatableViaDependencyInjection threw exception:
System.AggregateException: One or more errors occurred. ---> System.NullReferenceException: Object reference not set to an instance of an object.
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
Ninject.Planning.Planner.GetPlan(Type type)
Ninject.Activation.Providers.StandardProvider.Create(IContext context)
Ninject.Activation.Context.Resolve()
Ninject.KernelBase.<Resolve>b__9(IContext context)
System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
Ninject.ResolutionExtensions.Get(IResolutionRoot root, Type service, IParameter[] parameters)
Modus.Tests.Modules.ModuleTest.<AllRepositoriesShouldBeCreatableViaDependencyInjection>b__6(Type repositoryType) in C:\usr\local\work\Modus\ModusTest\Modules\ModuleTest.cs: line 78
System.Linq.Parallel.ForAllOperator`1.ForAllEnumerator`1.MoveNext(TInput& currentElement, Int32& currentKey)
System.Linq.Parallel.ForAllSpoolingTask`2.SpoolingWork()
System.Linq.Parallel.SpoolingTaskBase.Work()
System.Linq.Parallel.QueryTask.BaseWork(Object unused)
System.Linq.Parallel.QueryTask.<.cctor>b__0(Object o)
System.Threading.Tasks.Task.InnerInvoke()
System.Threading.Tasks.Task.Execute()
System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
System.Linq.Parallel.SpoolingTask.SpoolForAll[TInputOutput,TIgnoreKey](QueryTaskGroupState groupState, PartitionedStream`2 partitions, TaskScheduler taskScheduler)
System.Linq.Parallel.DefaultMergeHelper`2.System.Linq.Parallel.IMergeHelper<TInputOutput>.Execute()
System.Linq.Parallel.MergeExecutor`1.Execute()
System.Linq.Parallel.MergeExecutor`1.Execute[TKey](PartitionedStream`2 partitions, Boolean ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, Boolean isOrdered, CancellationState cancellationState, Int32 queryId)
System.Linq.Parallel.PartitionedStreamMerger`1.Receive[TKey](PartitionedStream`2 partitionedStream)
System.Linq.Parallel.ForAllOperator`1.WrapPartitionedStream[TKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, Boolean preferStriping, QuerySettings settings)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2 inputStream)
System.Linq.Parallel.SelectQueryOperator`2.WrapPartitionedStream[TKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, Boolean preferStriping, QuerySettings settings)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2 inputStream)
System.Linq.Parallel.WhereQueryOperator`1.WrapPartitionedStream[TKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, Boolean preferStriping, QuerySettings settings)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2 inputStream)
System.Linq.Parallel.WhereQueryOperator`1.WrapPartitionedStream[TKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, Boolean preferStriping, QuerySettings settings)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2 inputStream)
System.Linq.Parallel.SelectManyQueryOperator`3.WrapPartitionedStreamNotIndexed[TLeftKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, QuerySettings settings)
System.Linq.Parallel.SelectManyQueryOperator`3.WrapPartitionedStream[TLeftKey](PartitionedStream`2 inputStream, IPartitionedStreamRecipient`1 recipient, Boolean preferStriping, QuerySettings settings)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2 inputStream)
System.Linq.Parallel.ListQueryResults`1.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
System.Linq.Parallel.QueryOperator`1.GetOpenedEnumerator(Nullable`1 mergeOptions, Boolean suppressOrder, Boolean forEffect, QuerySettings querySettings)
System.Linq.Parallel.ForAllOperator`1.RunSynchronously()
System.Linq.ParallelEnumerable.ForAll[TSource](ParallelQuery`1 source, Action`1 action)
Modus.Tests.Modules.ModuleTest.AllRepositoriesShouldBeCreatableViaDependencyInjection() in C:\usr\local\work\Modus\ModusTest\Modules\ModuleTest.cs: line 76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment