在NServiceBus 6中进行程序集扫描时出现异常

本文关键字:扫描 异常 程序集 NServiceBus | 更新日期: 2023-09-27 17:57:59

我正在构建一个ASP。NET核心应用程序,该应用程序引用类库项目。这个类库试图设置一个端点。自从我加入微软以来。AspNetCore。身份EntityFrameworkCore我得到以下异常:

{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.
}

当我尝试启动端点(endpoint.start…)时,会发生此异常

因为我认为当我排除程序集系统时,异常可能会消失。互动的Async.dll扫描后我更改了端点配置代码:

endpointConfiguration.ExcludeAssemblies("System.Interactive.Async.dll", "System.Interactive.Async");

但不幸的是,这没有任何效果。例外情况保持不变。

顺便问一下,现在有人知道我如何排除所有的Microsoft.*和System.*DLL吗?ASP。NET Core将所有这些DLL放入bin目录中。因此,我有100多个这样的DLL,初始扫描需要很长时间。

在NServiceBus 6中进行程序集扫描时出现异常

不幸的是,我的语言专业知识是糟糕的英语和糟糕的c#,所以我认为你会遇到类似的错误,因为我在扫描时试图加载程序集及其依赖树,但失败了。要回答您关于排除ServiceBus 6+中的文件的问题,我个人认为他们删除了AllAssemblies Exclude功能,对我们造成了伤害,您可以执行以下操作。

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());

这解决了我在配置文件中绑定重定向的所有第三方代码的问题,扫描程序不尊重这些代码,只允许ServiceBus程序集和我的消息dll通过。我想你可能解决了这个问题,但我讨厌没有答案的问题,尤其是其他人需要帮助的好问题。