【问题标题】:Exception while assembly scan in NServiceBus 6NServiceBus 6 中的程序集扫描时出现异常
【发布时间】:2016-07-21 14:03:10
【问题描述】:

我正在构建一个引用类库项目的 ASP.NET Core 应用程序。此类库尝试设置端点。由于我已包含 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# asp.net nservicebus


    【解决方案1】:

    不幸的是,我的语言专业知识很差,英语和 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 流过。我假设您可能解决了这个问题,但我讨厌没有答案的问题,尤其是其他人需要帮助的好问题。

    【讨论】:

    • 为什么使用 Assembly.GetAssembly(typeof(ServiceMain)).Location 而不是 Directory.GetCurrentDirectory()?
    猜你喜欢
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-07
    • 1970-01-01
    相关资源
    最近更新 更多