NServiceBus 6 中的程序集扫描时出现异常
Exception while assembly scan in NServiceBus 6
我正在构建一个 ASP.NET 核心应用程序,它引用了一个 class 库项目。此 class 库尝试设置端点。由于我已经包括 Microsoft.AspNetCore.Identity.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...)
因为我认为当我从扫描中排除程序集 System.Interactive.Async.dll 时异常可能会消失,所以我更改了端点配置代码:
endpointConfiguration.ExcludeAssemblies("System.Interactive.Async.dll", "System.Interactive.Async");
但遗憾的是这没有效果。异常保持不变。
顺便说一句,现在有人知道我如何排除所有 Microsoft.* 和 System.* DLL 吗? ASP.NET Core 将所有这些 DLL 放入 bin 目录中。因此我有超过 100 个这样的 DLL,并且初始扫描需要很长时间。
不幸的是,我的语言专业知识是糟糕的英语和糟糕的 c#,所以我假设您遇到了类似的错误,就像我在尝试加载程序集及其依赖树并失败时进行扫描时遇到的错误一样。要回答有关在 nServiceBus 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());
这解决了我在扫描器不尊重的配置文件中绑定重定向的所有第三方代码的问题,只允许 nServiceBus 程序集和我的消息 dll 流过。我想您可能已经解决了这个问题,但我讨厌没有答案的问题,尤其是其他人需要帮助的好问题。
我正在构建一个 ASP.NET 核心应用程序,它引用了一个 class 库项目。此 class 库尝试设置端点。由于我已经包括 Microsoft.AspNetCore.Identity.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...)
因为我认为当我从扫描中排除程序集 System.Interactive.Async.dll 时异常可能会消失,所以我更改了端点配置代码:
endpointConfiguration.ExcludeAssemblies("System.Interactive.Async.dll", "System.Interactive.Async");
但遗憾的是这没有效果。异常保持不变。
顺便说一句,现在有人知道我如何排除所有 Microsoft.* 和 System.* DLL 吗? ASP.NET Core 将所有这些 DLL 放入 bin 目录中。因此我有超过 100 个这样的 DLL,并且初始扫描需要很长时间。
不幸的是,我的语言专业知识是糟糕的英语和糟糕的 c#,所以我假设您遇到了类似的错误,就像我在尝试加载程序集及其依赖树并失败时进行扫描时遇到的错误一样。要回答有关在 nServiceBus 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());
这解决了我在扫描器不尊重的配置文件中绑定重定向的所有第三方代码的问题,只允许 nServiceBus 程序集和我的消息 dll 流过。我想您可能已经解决了这个问题,但我讨厌没有答案的问题,尤其是其他人需要帮助的好问题。