mercredi 6 juillet 2016

Dynamically loaded DLL not being found by code

I have an executable that loads a second assembly by reflection, and executes a method on that second assembly also via reflection.

Within this method, I need to dynamically load some assemblies that the code needs. I have this

foreach (var a in assembliesToLoad)
                {
                    Log.Info("Loading assembly " + Path.Combine(assemblyPath, a));
                    Assembly.LoadFile(Path.Combine(assemblyPath, a));                    
                }

The log output of this is

2016-07-06 15:49:54,142 INFO FixingsActionExecutor - Loading assembly \wycvwwebd016\Centrica.CE.SE.ControlEngine.Service\ActionAssemblies\DataGenic.DataLibrary.dll

2016-07-06 15:49:54,244 INFO FixingsActionExecutor - Loading assembly \wycvwwebd016\Centrica.CE.SE.ControlEngine.Service\ActionAssemblies\DataGenic.Gdm.API.dll

2016-07-06 15:49:54,324 INFO FixingsActionExecutor - Loading assembly \wycvwwebd016\Centrica.CE.SE.ControlEngine.Service\ActionAssemblies\Newtonsoft.Json.dll

I have confirmed by entering those UNC's into explorer that those three DLLs definitely exist.

However, the next line of code is this

var requestModel = products.Select(p => JsonConvert.DeserializeObject<DatagenicRequestModel>(p.Value)).ToList();

This throws the following exception

2016-07-06 15:49:54,381 ERROR FixingsActionExecutor - Error while executing Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.,, at Centrica.CE.SE.StorageActions.FixingsActionExecutor.b__2(JobInstanceConfig p) at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext()
at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) at Centrica.CE.SE.StorageActions.FixingsActionExecutor.Execute(Object[] parameters)

Which seems to imply the dynamic loading of the above assembly hasn't worked. Is it asynchronous? Do I have to do something else before trying to run the JSON code? What am I doing wrong?





Aucun commentaire:

Enregistrer un commentaire