Hello,
I have an application with a modular monolith architecture. As part of this we have multiple endpoints, typically one endpoint per module which are using azure service bus as the messaging infrastructure. In total we have 8 endpoints which are starting up, one at a time when the monolithic web application is starting up. Occasionally in production we get the below error.
This only happens on app services that are processing messages. We have some app services running the same code with read-only endpoints that have never experienced this issue. That makes sense as it appears the error is coming from some assembly scanning code, but I am not really sure where to go from here. We are unable to reproduce in any test environments and it happens on production maybe once 1/20 deployments.
Just wondering if anybody has any suggestions on areas to further my investigation?
Assembly Scanning Code:
internal AssemblyScannerConfiguration IncludeOnly( AssemblyScannerConfiguration configuration, params Assembly[] assembliesToInclude)
{
List<string> includedAssemblyNames = assembliesToInclude.Select(b => $"{b.GetName().Name}.dll").ToList();
string[] files = _fileListProvider.GetFiles($"{AppDomain.CurrentDomain.BaseDirectory}", "*.dll",SearchOption.AllDirectories);
string[] excludedAssemblyNames = files
.Select(path => Path.GetFileName(path))
.Where(a => !includedAssemblyNames.Contains(a))
.Where(a => !a.ToLower().Contains("nservicebus."))
.ToArray();
configuration.ExcludeAssemblies(excludedAssemblyNames);
return configuration;
}
Exception:
System.IO.FileLoadException: Could not load file or assembly ‘NServiceBus.Core.dll’ or one of its dependencies. An assertion failure has occurred. (Exception from HRESULT: 0x8007029C)
File name: ‘NServiceBus.Core.dll’ —> System.Runtime.InteropServices.COMException (0x8007029C): An assertion failure has occurred. (Exception from HRESULT: 0x8007029C)
at System.Reflection.AssemblyName.nGetFileInformation(String s)
at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
at NServiceBus.AssemblyValidator.ValidateAssemblyFile(String assemblyPath, Boolean& shouldLoad, String& reason)
at NServiceBus.Hosting.Helpers.AssemblyScanner.TryLoadScannableAssembly(String assemblyPath, AssemblyScannerResults results, Assembly& assembly)
at NServiceBus.Hosting.Helpers.AssemblyScanner.ScanAssembliesInDirectory(String directoryToScan, List`1 assemblies, AssemblyScannerResults results)
at NServiceBus.Hosting.Helpers.AssemblyScanner.GetScannableAssemblies()
at NServiceBus.AssemblyScanningComponent.Initialize(Configuration configuration, SettingsHolder settings)
at NServiceBus.HostCreator.d__1.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NServiceBus.Endpoint.d__1.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Messaging.Core.EndpointCreation.EndpointBuilder.d__30.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Web.App_Start.NServiceBus.NServiceBusConfig.d__2.MoveNext() in C:\a\1\s\Web\App_Start\NServiceBus\NServiceBusConfig.cs:line 62
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Web.MvcApplication.Application_Start() in C:\a\1\s\Global.asax.cs:line 73
Application is .NET Framework 4.6.2
Using NServiceBus NuGetPackage v7.6.0