ModuleInitializer fails with ArgumentNullException is JSON configuration is missing certain settings

Issue #11 new
Pavel Veller created an issue

I haven't yet figured out why exactly but here's what I am experiencing:

[ArgumentNullException: Value cannot be null.
Parameter name: first]
   System.Linq.Enumerable.Union(IEnumerable`1 first, IEnumerable`1 second) +5926451
   <>c__DisplayClass0_0.<Initialize>b__1(MethodBase method) +1679
   System.Collections.Generic.List`1.ForEach(Action`1 action) +14316743
   <>c__DisplayClass0_0.<Initialize>b__0(Tuple`2 tuple) +236
   System.Collections.Generic.List`1.ForEach(Action`1 action) +14316743
   ModuleInitializer.Initialize() +574

[Exception: An exception occurred while Bootstrapping {Code}Cop]
   ModuleInitializer.Initialize() +1518
   CodeCop.Core.Cop.Intercept() +216

The ModuleInitializer does something along the lines of:

IEnumerable<string> message;

// and later

IEnumerable<string> enumerable = Enumerable.Union<string>(message, (IEnumerable<string>) list);

I don't know (yet) why message remains null but if message was initialized to an empty List it would not fail like it does. More detailed logging that would tell me what I am missing with the message thing would help as well. Maybe I defined my method signatures wrong?

Comments (9)

  1. Pavel Veller reporter

    And I by now know it's not the method signatures. I put it to * and I am still getting this error. I wish I knew what this was for:

    message = messageQueue.GetMessage<IEnumerable<string>>(command.CommandId);
    

    It would help me understand what am I missing.

  2. Pavel Veller reporter

    I moved away from GlobalInterceptors to se if it would help (I figured the code path in ModuleInitializer that I was hitting was specific to global interceptors). I am now experiencing a different error:

    [NullReferenceException: Object reference not set to an instance of an object.]
       <>c__DisplayClass0_0.<Initialize>b__1(MethodBase method) +742
       System.Collections.Generic.List`1.ForEach(Action`1 action) +14316742
       <>c__DisplayClass0_0.<Initialize>b__0(Tuple`2 tuple) +235
       System.Collections.Generic.List`1.ForEach(Action`1 action) +14316742
       ModuleInitializer.Initialize() +573
    
    [Exception: An exception occurred while Bootstrapping {Code}Cop]
       ModuleInitializer.Initialize() +1518
       CodeCop.Core.Cop.Intercept() +216
    
  3. Pavel Veller reporter

    It appears as if Cop is very sensitive to JSON configuration not only being right but also having certain pieces present. I added empty [] for GlobalInterceptors and 'GenericArguments` and these errors went away.

    Wouldn't it be better if Cop had JSON validation built-in that would fail with a very friendly Exception telling what what I am missing? sensible defaults would also help I think.

    I no longer have errors - the bootstrapping seems to be spinning and spinning (still waiting) but no more type loading or Null Reference errors. I will keep you guys posted.

  4. Pavel Veller reporter

    sure. it no longer fails once I added empty [] for the things I thought I could omit. It didn't bootstrap - and I am looking into it now - but at least I am past the exceptions.

    To reproduce

    • Try config without GenericArguments specified and/or without GlobalInterceptors

    I believe those collections will be initialized to null if JSON doesn't have empty [ ]. If the default value was set to something like Enumerable.Empty<string>() I would probably not see the errors. Let me know if you still need my config file.

    btw, I found out about CodeCop thanks to your appearance on the .NET Rocks. Cool idea! Just need to get it to work :))

  5. Ricardo Barbosa

    Glad you worked that out Pavel :)

    Yeah you're totally right, we need more friendly exception messages at bootstrap.

    Thank you so much, for your kind words! We'll get it working on your app no worries.

    This will be filed as an internal improvement and will be fixed on next version.

    -- Ricardo

  6. Ricardo Barbosa

    Hi Pavel,

    I've just pushed v1.3.3 to nuget where all this issues are corrected.

    You can now omit GenericArguments as well as GlobalInterceptors from the JSON file.

    I added also a more friendly error message when JSON parsing errors occur due to bad structure or invalid characters.

    Please tell us if that fixed this issue.

    Thanks,

    --Ricardo

  7. Log in to comment