Microsoft.StreamProcessing导致程序加载异常

时间:2019-06-09 21:14:16

标签: c# .net winforms mef

我有一个稍微复杂的交易应用程序,可以处理许多事件消息。这是一个Windows MEF应用程序,它会自动在assemblies上加载runtime

我决定尝试Microsoft.StreamProcessing将事件转换为IStreamable。我移动缓慢。首先,我只是通过nuget将程序集添加到了project中。然后添加

using Microsoft.StreamProcessing;

代码,但未声明任何类型。运行正常。

接下来,我在代码中添加了行:

IStreamable<Empty, IQuote> markeDatatStream;

这就是我所做的。我没有以任何方式使用它,只是添加了那一行。这次,在程序加载时,出现以下异常。当我查看建议的LoaderExceptions字段时,我得到:

{"Could not load file or assembly 'System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"System.Runtime.Loader, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}

如果我从代码中删除一行

IStreamable<Empty, IQuote> markeDatatStream;

它工作正常。

完整例外:

System.Reflection.ReflectionTypeLoadException
  HResult=0x80131602
  Message=Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
  Source=mscorlib
  StackTrace:
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition)
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
   at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TryGetExports(ExportProvider provider, ComposablePart part, ImportDefinition definition, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable`1 imports, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part)
   at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports)
   at System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart part)
   at System.ComponentModel.Composition.Hosting.CompositionServices.TryInvoke(Action action)
   at System.ComponentModel.Composition.Hosting.ComposablePartExportProvider.Compose(CompositionBatch batch)
   at Trader.MainForm.InitializeTradingEngine() in C:\Users\idf\Projects\Trader-Orig-Working\Trader\Trader\MainForm.cs:line 200
   at Trader.MainForm..ctor(String logFilePath) in C:\Users\idf\Projects\Trader-Orig-Working\Trader\Trader\MainForm.cs:line 113
   at Trader.Program.Main() in C:\Users\idf\Projects\Trader-Orig-Working\Trader\Trader\Program.cs:line 231

1 个答案:

答案 0 :(得分:1)

这里的问题可能是strong naming

总结:

如果您包含库A(该库是强命名的),并且在程序集版本1.0.0.0中使用库B 并且您正在使用库B,但使用程序集版本1.1.0.0,则将出现加载错误-并出现令人困惑的错误“系统找不到指定的文件”

然后您需要绑定:

<dependentAssembly>
  <assemblyIdentity name="B"     publicKeyToken="32ab4ba45e0a69a1"     culture="en-us" />
  <bindingRedirect oldVersion="1.0.0.0" newVersion="1.1.0.0" />
</dependentAssembly>

因此,有人在您的应用程序中构建了System.Runtime.Loader,版本= 4.0.0.0,但是您可能(可能通过另一个库)提供了System.Runtime.Loader的另一个版本。

另一个选择是将System.Runtime.Loader版本添加到GAC