gautema/CQRSlite

Exception when sending command

orendin opened this issue · 4 comments

Hey guys

Just wanted to log that, with the latest build, I am getting an exception when I try to send a command via the Router:

System.NullReferenceException: Object reference not set to an instance of an object.
   at CQRSlite.Infrastructure.DynamicInvoker.GetTypeAndHash[T](T obj, String methodname, Object[] args, Type& type, Int32& hash)
   at CQRSlite.Infrastructure.DynamicInvoker.Invoke[T](T obj, String methodname, Object[] args)
   at CQRSlite.Routing.RouteRegistrar.<>c__DisplayClass3_0.<InvokeHandler>b__5(Object x, CancellationToken token)
   at CQRSlite.Routing.Router.<>c__DisplayClass1_0`1.<RegisterHandler>b__0(IMessage message, CancellationToken token)
   at CQRSlite.Routing.Router.Send[T](T command, CancellationToken cancellationToken)

Seems to be stemming from the latest change to PrivateReflectionDynamicObject, which was changed to DynamicInvoker with some changes to the hashing.

Cheers

Ben

Hi.

Do you have any possibility to recreate this issue? Any code would be great.

I'll try to reproduce the issue in the sample or unit tests on Monday.
I'll let you know how I go and possibly send some code or a pull request.

Thanks

Ben

Hi there

I found the issue. It was my own fault, really. But maybe a you could add a more useful error message.
When I added a new dependency to inject in the Startup.cs, I accidentally provided the wrong type. That means during resolution time, it could not find a type for constructor injection.

This is easily reproducible by just adding e.g. an unregistered interface to the InMemoryEventStore in the Sample like so:
`

public interface IFailedEntirely { }
...
public InMemoryEventStore(IEventPublisher publisher, IFailedEntirely failedEntirely)
    {
        _publisher = publisher;
    }

`

Then run the sample, click on add, provide a name and submit. Boom!
Because the error message is rather generic and since the mistake was rather subtle, I did not spot it very easily.

Thanks for your help!

Ben

Ok. I figured it might be the case. I've already added a bit better error message, but will consider making a custom exception for it in the future.