Microsoft.StreamProcessing causes exception on program loading

0

I have a somewhat complex trading application that handles lots of Event messages. It is a Windows MEF application that loads assemblies automatically at runtime.

I decided to try Microsoft.StreamProcessing to convert events to IStreamable. I moved in slow steps. First, I just added the assembly through nuget to my project. Then added

using Microsoft.StreamProcessing;

to the code, but did not declare any types. Runs fine.

Next, I added a single line to the code:

IStreamable<Empty, IQuote> markeDatatStream;

That's all I did. I am not using it in any way, just added that one line. This time, while the program is loading, I get the following exception. When I look inside the recommended LoaderExceptions field, I get:

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

If I remove the single line from the code

IStreamable<Empty, IQuote> markeDatatStream;

It works fine.

The full exception:

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
c#
.net
winforms
mef
asked on Stack Overflow Jun 9, 2019 by Ivan • edited Jun 10, 2019 by Ivan

1 Answer

1

The problem here is probably strong naming.

In summary:

If you include library A, which is strong named, and uses library B with assembly-version 1.0.0.0 and you are using Library B, but with assembly-version 1.1.0.0, then you will get loads errors - with the confusing error "The system cannot find the file specified"

You need then a binding:

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

So someone builds to System.Runtime.Loader, Version=4.0.0.0, in your application, but you're probably (maybe via another library) providing another version of System.Runtime.Loader.

another option is add the System.Runtime.Loader versions to the GAC

answered on Stack Overflow Jun 13, 2019 by Julian

User contributions licensed under CC BY-SA 3.0