I am building a ASP.NET Core application which references a class library project. This class library tries to set up an endpoint. Since I have included Microsoft.AspNetCore.Identity.EntityFrameworkCore I get the following exception:
{System.IO.FileLoadException: Die Datei oder Assembly "System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040)
Dateiname: "System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
bei System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
bei System.Reflection.RuntimePropertyInfo.get_Signature()
bei System.Reflection.RuntimePropertyInfo.get_PropertyType()
bei NServiceBus.Conventions.<>c.<.ctor>b__21_2(PropertyInfo p)
bei NServiceBus.Conventions.IsEncryptedProperty(PropertyInfo property)
=== Zustandsinformationen vor Bindung ===
LOG: DisplayName = System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///D:/enio_tfs/enio.InvoiceR/Main/enio.InvoiceR.WebApp/bin/Debug/net461/win7-x64/
LOG: Ursprünglicher PrivatePath = NULL
Aufruf von Assembly : EntityFramework.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60.
===
LOG: Diese Bindung startet im default-Load-Kontext.
LOG: Die Anwendungskonfigurationsdatei wird verwendet: D:\enio_tfs\enio.InvoiceR\Main\enio.InvoiceR.WebApp\bin\Debug\net461\win7-x64\enio.InvoiceR.WebApp.exe.Config
LOG: Die Hostkonfigurationsdatei wird verwendet:
LOG: Die Computerkonfigurationsdatei von C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config wird verwendet.
LOG: Verweis nach der Richtlinie: System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Download von neuem URL file:///D:/enio_tfs/enio.InvoiceR/Main/enio.InvoiceR.WebApp/bin/Debug/net461/win7-x64/System.Interactive.Async.DLL.
WRN: Der Vergleich des Assemblynamens führte zum Konflikt: Hauptversion.
ERR: Das Setup der Assembly konnte nicht abgeschlossen werden (hr = 0x80131040). Die Suche wurde beendet.
}
This exceptions occurs when I try to start the endpoint (Endpoint.Start...)
As I thought that the exception might go away when I exclude the assembly System.Interactive.Async.dll from scanning I have changed the endpoint configuration code:
endpointConfiguration.ExcludeAssemblies("System.Interactive.Async.dll", "System.Interactive.Async");
But unfortunately this has no effect. The exception remains the same.
By the way does anyone now how I can exclude all Microsoft.* and System.* DLLs? ASP.NET Core puts all those DLLs into the bin directory. Therefore I have over 100 such DLLs and the initial scanning takes ages.
Unfortunately my language expertise is bad english and bad c#, so I assume you are getting a similar error as I did with the scanning trying to load assemblies and their dependency trees and failing. To answer your question about excluding files in nServiceBus 6+, which I personally I think they did us a disservice by removing the AllAssemblies Exclude functionality, you could do the following.
var endpointConfiguration = new EndpointConfiguration("MyEndpoint");
var fullPath = Assembly.GetAssembly(typeof(ServiceMain)).Location;
var directory = new DirectoryInfo(Path.GetDirectoryName(fullPath));
var files = directory.GetFiles("*.dll", SearchOption.TopDirectoryOnly);
var excludedFiles = new List<string>();
foreach (var file in files) {
if (!file.Name.Contains("NServiceBus") && !file.Name.Contains("Messages")) {
excludedFiles.Add(file.Name);
}
}
endpointConfiguration.ExcludeAssemblies(excludedFiles.ToArray());
This solved my problem for all third party code that I had binding redirects in the config file that the scanner didn't respect, by only allowing nServiceBus assemblies and my message dlls to flow through. I assume you probably solved this problem, but I hate unanswered questions, especially good ones that other people are going to need help with.