EDIT heres the github page if people want to have a look
https://github.com/brandongrossutti/EventStore
I am having a very odd issue and cant quite figure the root cause.
I have a zeromq subscriber on its own thread.
When it gets a message it calls a delegate and then goes into a messagehandler which eventually gets to this dynamic call
private void OnEvent(IEvent @event, bool isNew)
{
string eventName = "On" + @event.GetType().Name.Replace("Event", "");
dynamic inheritingClass = this;
MethodInfo method = inheritingClass.GetType().GetMethod(eventName);
method.Invoke(inheritingClass, new object[] { @event });
if (isNew)_uncommitedEvents.Add(@event);
}
it dies on the invoke and the call stack and exception dont show a thing.
If i step through slowly, it seems to work just fine. Very confused.
thanks in advance
EDIT:
heres the badly written code for the thread that starts the subscriber
private readonly IHandlerResolver _resolver;
private readonly Thread _subscriberThread;
public MessageSubscriber(OnTheWireBusConfiguration configuration, IHandlerResolver resolver)
{
_resolver = resolver;
_subscriberThread = new Thread(RecieveMessages);
_subscriberThread.Start(new object[] { configuration, resolver, new Action<Message>(ProcessMessage) });
}
private static void RecieveMessages(object o)
{
object[] obj = o as object[];
OnTheWireBusConfiguration configuration = (OnTheWireBusConfiguration)obj[0];
IHandlerResolver resolver = (IHandlerResolver)obj[1];
Action<Message> handlerDelegate = (Action<Message>) obj[2];
using (var context = new Context(configuration.MaxThreads))
{
using (Socket subscriber = context.Socket(SocketType.SUB))
{
subscriber.Subscribe("", Encoding.Unicode);
subscriber.Connect("tcp://localhost:5565");
while (true)
{
byte[] buffer = subscriber.Recv();
Message message = (Message) configuration.Deserialize(buffer);
Console.WriteLine(message);
handlerDelegate(message);
//resolver.ExecuteHandler(message);
}
}
}
}
public void ProcessMessage(Message message)
{
_resolver.ExecuteHandler(message);
}
EDIT#2
Call Stack
GHI.EventRepository.dll!GHI.EventRepository.AggregateRoot.OnEvent(GHI.EventRepository.IEvent event, bool isNew) Line 39 C#
GHI.EventRepository.dll!GHI.EventRepository.AggregateRoot.OnEvent(GHI.EventRepository.IEvent event) Line 29 + 0x12 bytes C#
GHI.TestDomain.dll!GHI.TestDomain.Model.TestAggregateRoot.TestAggregateRoot(System.Guid id) Line 15 + 0x59 bytes C#
GHI.TestDomain.dll!GHI.TestDomain.Handlers.CreateNewTestAggregateRootCommandHandler.HandleMessage(GHI.TestDomain.Messages.CreateNewTestAggregateRootCommand message) Line 20 + 0x62 bytes C#
[Native to Managed Transition]
GHI.Bus.dll!GHI.Bus.HandlerResolver.ExecuteHandler(GHI.Bus.Message message) Line 40 + 0x95 bytes C#
GHI.Bus.ZeroMQ.dll!GHI.Bus.ZeroMQ.MessageSubscriber.ProcessMessage(GHI.Bus.Message message) Line 48 + 0x38 bytes C#
GHI.Bus.ZeroMQ.dll!GHI.Bus.ZeroMQ.MessageSubscriber.RecieveMessages(object o) Line 39 + 0x13 bytes C#
mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x173 bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xeb bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x3b bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart(object obj) + 0x5d bytes
[Native to Managed Transition]
[Appdomain Transition]
[Native to Managed Transition]
I can pop this onto Github if easier
EDIT #4
Thanks for everyones help, glad i could remove the dynamic keyword from that bit of code.
Dynamic was not the issue it was my locking way up the stack, thank you again, I have upvoted thos that mentioned dynamic issue and will accept the answer below
I’m not familiar with zeromq, but looking at your
OnEventmethod, I don’t seedynamicas necessary. What happens when you don’t usedynamic, and replace the method with this?If there’s no change to the behavior, then the problem may be elsewhere.
(Probably want to add a
if(method != null)around the Invoke, unless you’re absolutely sure it’ll be there all the time.)