TypeDiscovery.cs Locate method

Dec 22, 2010 at 9:07 PM

Why Monitor.Agent should load all assemblies in the bin folder?

2010-12-22 22:50:21,917 [1] ERROR MonitorWang [(null)] - MonitorWang System Failure. IncidentId:=4ac886c3-b78b-4989-ac35-bed746a7505a; Details:=System.BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
   at System.Reflection.Assembly.nLoadFile(String path, Evidence evidence)
   at System.Reflection.Assembly.LoadFile(String path)
   at MonitorWang.Core.TypeDiscovery.<Locate>b__4(String assemblyName) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Core\TypeDiscovery.cs:line 109
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at MonitorWang.Core.TypeDiscovery.Locate(String[] interfaceTypes, Type[]& matchingTypes, Predicate`1 filter) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Core\TypeDiscovery.cs:line 118
   at MonitorWang.Core.TypeDiscovery.Discover(String[] interfaceTypes, Type[]& matchingTypes, Predicate`1 filter) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Core\TypeDiscovery.cs:line 89
   at MonitorWang.Core.TypeDiscovery.Discover(String interfaceType, Type[]& matchingTypes, Predicate`1 filter) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Core\TypeDiscovery.cs:line 66
   at MonitorWang.Core.TypeDiscovery.Discover[T](Type[]& matchingTypes, Predicate`1 filter) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Core\TypeDiscovery.cs:line 43
   at MonitorWang.Core.TypeDiscovery.Discover[T](Type[]& matchingTypes) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Core\TypeDiscovery.cs:line 32
   at MonitorWang.Core.Loaders.ProfileLoader.Load(String name, IRoleProfile& profile) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Core\Loaders\ProfileLoader.cs:line 35
   at MonitorWang.Core.Loaders.ProfileLoader.Find(String name, IRoleProfile& profile) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Core\Loaders\ProfileLoader.cs:line 21
   at MonitorWang.Agent.Startup.LoadProfile() in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Agent\Startup.cs:line 80
   at MonitorWang.Agent.Startup.Main(String[] args) in c:\Projects\MonitorWang\Releases\v1.0.4.0\Source\MonitorWang.Agent\Startup.cs:line 20

Coordinator
Dec 23, 2010 at 8:25 AM

Hi,

The startup code (Startup.cs\Main()) scans all assemblies looking for any class that implments the IRoleProfile interface.

You can pass the name of the profile you wish to load on the cmd line params and it tries to find the Profile by looking at all the classes it found in the scan to match the name.

It scans the assemblies as I think this is better than having to configure it - I'm trying very hard to reduce the amount of configuration required by MonitorWang - so scanning the assemblies to discover the implementations seemed like the best route.

I assume from the error (BadImage) that you have a non .Net dll in the bin folder. I'll look at creating an exclude list so that you can specify assemblies not to scan - or at the least put a try/catch to skip non loadable dlls.

Cheers,

James

Coordinator
Dec 23, 2010 at 7:58 PM

Ok, I've added a TypeDiscoveryConfig component and associated config to the config\role.castle.config file; this is now used by the TypeDiscovery component to filter out any assemblies you do not wish to be scanned.

Essentially this feature allows you to create an exclusion list of files (dll/exe) that MonitorWang will skip when scanning the bin folder for types. It allows you to add new entries for dll's you might add that do not have any direct use to MonitorWang eg: a 3rd party dll required for a custom HealthCheck or a non .Net dll.

This will be released in v1.0.5 - due for release very shortly.

Hope this fixes the problem with MonitorWang scanning the bin folder too aggresively.

J