We had a nasty little bug in one of our development stage Episerver projects. Everything ran and worked smoothly, but one day Episerver’s error logs started to report an exception regarding the Episerver.Find.Commerce module. However, the site seemed to work properly so the bug hunt could be scheduled to another day.
Things escalated when Episerver made some error handling changes in the Episerver.Find.Commerce version 10.1.1.
When the new version was applied to our project, the only thing we were able to get was a 500 error. Logfiles told the same story as before, but because of the version update there was no more excuses to move the bug hunt any further.
|2018-04-17 12:15:00,462  ERROR EPiServer.Find.Commerce.FindCommerceInitializationModule: Could not apply catalog content conventions.|
|System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.|
|at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)|
|at EPiServer.Find.ClientConventions.NestedConventions.<>c__DisplayClass17_0.<MarkAllImplementationsAsNested>b__1(Assembly a)|
|at EPiServer.Find.Helpers.ListExtensions.ForEach[T](IEnumerable`1 value, Action`1 action)|
|at EPiServer.Find.ClientConventions.NestedConventions.MarkAllImplementationsAsNested(Type declaringType, String name)|
|at EPiServer.Find.ClientConventions.NestedConventions.ForInstancesOf[TSource,TListItem](Expression`1 exp)|
|at EPiServer.Find.ClientConventions.NestedConventionItemInstanceWrapper`1.Add[TListItem](Expression`1 expr)|
|at EPiServer.Find.Commerce.CatalogContentClientConventions.ApplyNestedConventions(NestedConventions nestedConventions)|
|at EPiServer.Find.Commerce.CatalogContentClientConventions.ApplyConventions(IClientConventions clientConventions)|
|at EPiServer.Find.Commerce.FindCommerceInitializationModule.Initialize(InitializationEngine context)|
First suspicions were that there must have been something wrong with our initialization modules regarding the Episerver.Find.Commerce. Through “extensive” debugging and basically removing every custom code that could even remotely have an impact to the Find.Commerce. But. Only one thing was left, the same error in the error log.
Now what? Maybe cleaning the solution, rebuilding it, removing asp.net temporary files, removing bin and obj -folders. Perhaps the previous installation of the nugets failed for some reason. Removed nugets and reinstalled them. Restarted Visual Studio.
Still. The same error was there.
Ok. At this point it was obvious that there must be a DLL missing or some other reference related problem. And it probably isn’t even related to Episerver.
Even though the error in the log indicated that there might be a problem in Episerver.Find.Commerce, there was also another hint regarding how to get more specific information about those missing references.
Key to resolve this issue were the loader exceptions.
While I first started to investigate this, I noticed that some our custom initialization modules where firing and I was able to get a breakpoint there before the 500 error. That was a one place to put some temporary debugging code in.
|foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())|
|catch (Exception ex)|
|if (ex is System.Reflection.ReflectionTypeLoadException)|
|var typeLoadException = ex as ReflectionTypeLoadException;|
|var loaderExceptions = typeLoadException.LoaderExceptions; // Breakpoint|
And there it was. A third-party integration through DI (structuremap), having not any other relation to Episerver, was missing a DLL, but it was hidden behind someway misleading error information. After putting the DLL in place, everything started to work again, and the error was resolved.
So, the teaching of this story is: Check those loader exceptions first, as it was mentioned in the original error message…