JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
568 stars 119 forks source link

Scan exception when no assemblies found with cryptic message. #188

Closed robgha01 closed 4 years ago

robgha01 commented 4 years ago

The exception message thrown when "0" assemblies is found is "The data argument contains no data. Parameter Name: tasks" this dont say mush and need to get improved ex "Lamar could not find any assemblies matching ..." or just check if there is any assemblies and dont throw at all ?

System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=Ett undantagsfel har inträffat i målet för en aktivering.
  Source=mscorlib
  StackTrace:
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance[T]()
   at Lamar.ServiceRegistry.IncludeRegistry[T]()
   at BlueLeet.Core.DependencyResolution.IoC.<>c.<Initialize>b__0_0(ServiceRegistry c) in C:\Workspace\BlueLeet\BlueLeet.Core\BlueLeet.Core\DependencyResolution\IoC.cs:line 29
   at Lamar.ServiceRegistry.For(Action`1 configuration)
   at Lamar.Container..ctor(Action`1 configuration)
   at BlueLeet.Core.DependencyResolution.IoC.Initialize() in C:\Workspace\BlueLeet\BlueLeet.Core\BlueLeet.Core\DependencyResolution\IoC.cs:line 29
   at BlueLeet.Core.CoreBootstrapper.Start() in C:\Workspace\BlueLeet\BlueLeet.Core\BlueLeet.Core\App_Start\CoreBootstrapper.cs:line 36
   at BlueLeet.UCodeFirst.Tests.Unit.UCodeFirstHelperTests..ctor() in C:\Workspace\BlueLeet\BlueLeet.UCodeFirst\BlueLeet.UCodeFirst.Tests\Unit\UCodeFirstHelperTests.cs:line 19

Inner Exception 1:
ArgumentException: Uppgiftsargumentet innehåller inga uppgifter.
Parameternamn: tasks

The registration:

Other registrations here...
Scan(_ =>
{
    _.AssembliesFromApplicationBaseDirectory(assembly => assembly.HasAttribute<ModuleAttribute>());
    _.Convention<AnyConvention>();
});

The throwing code: Lamar.Scanning.TypeRepository:61

public static Task<TypeSet> FindTypes(IEnumerable<Assembly> assemblies, Func<Type, bool> filter = null)
{
    var tasks = assemblies.Select(ForAssembly).ToArray();
    return Task.Factory.ContinueWhenAll(tasks, assems =>
    {
        return new TypeSet(assems.Select(x => x.Result).ToArray(), filter);
    });
}

Edit: What would be nice behavior is having a error message that shows from what ServiceRegistry this is from this way it will be faster to locate a problem.

jeremydmiller commented 4 years ago

@robgha01 I think you might be misdiagnosing the root cause here. Looks to me like you're getting an exception in the constructor function of whatever ServiceRegistry you're finding rather than any kind of problem with type scanning itself.

jeremydmiller commented 4 years ago

I'm closing this one due to a lack of activity, and I don't think it's actually related to Lamar.