EventStore.ClientAPI.Embedded: type initializer issue & BadRequest issues

How do I fix such errors till fix is released? Currently getting

System.TypeInitializationException: The type initializer for ‘EventStore.Core.Messaging.MessageHierarchy’ threw an exception. —> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at EventStore.Core.Messaging.MessageHierarchy.<.cctor>b__1(Assembly assembly)
at System.Linq.Enumerable.d__313.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at EventStore.Core.Messaging.MessageHierarchy…cctor()
— End of inner exception stack trace —
at EventStore.Core.Bus.InMemoryBus…ctor(String name, Boolean watchSlowMsg, Nullable`1 slowMsgThreshold)
at EventStore.Core.ClusterVNode…ctor(TFChunkDb db, ClusterVNodeSettings vNodeSettings, IGossipSeedSource gossipSeedSource, InfoController infoController, ISubsystem[] subsystems)
at EventStore.ClientAPI.Embedded.EmbeddedVNodeBuilder.Build()
at WB.Tests.Integration.EventStore.with_in_memory_event_store.<.ctor>b__0() in F:\Tests\WB.Tests.Integration\EventStore\with_in_memory_event_store.cs:line 26

``

When initializing event store with the following code:

        var emptyEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0);
        node = EmbeddedVNodeBuilder.AsSingleNode()
            .RunInMemory()
            .WithInternalHttpOn(emptyEndpoint)
            .WithInternalTcpOn(emptyEndpoint)
            .WithExternalHttpOn(emptyEndpoint)
            .WithExternalTcpOn(emptyEndpoint)
            .Build();

        var startedEvent = new ManualResetEventSlim(false);
        node.MainBus.Subscribe(
            new AdHocHandler<UserManagementMessage.UserManagementServiceInitialized>(m => startedEvent.Set()));

        node.Start();

``

Thanks.

Pretty sure that is fixed by adding a reference to Protobuf-net

https://www.nuget.org/packages/protobuf-net/

Guessing without seeing the actual exception thrown that you need a reference to protobuf

Tried adding reference to this package. Still same error. But it doesn’t fail on second run. What else could be a reason? Maybe I can get more details somewhere in logs?

You are getting a type initializer exception have you looked at what it explains?

Depending on problems you may also want to look at fusion log

Finally was able to get loader message. Here it is Could not load file or assembly ‘ICSharpCode.NRefactory.CSharp, Version=5.0.0.0, Culture=neutral, PublicKeyToken=d4bfe873e7598c49’ or one of its dependencies. Not event sure that it is really related to EventStore, or NCrunch runner.

Given the assembly I can take a guess :slight_smile: We don't use anything related
to nrefactory but it sounds like something ncrunch would be using.

It looks like we’ve found a reason why starting node fails. There is a thread in RavenDB that says that code should not scan Raven.Database.dll. But it does get scanned because MessageHierarchy class in EventStore scans all assemblies loaded in CurrentDomain. Is there an extension point in EventStore where this scan can be disabled? How will it affect EventStore functionality?

Not as of now but easy enough to add can you create an issue? We use it to search for various plugins.

Cheers,

Greg

Thanks Greg. I’ve added issue #382.

Just got bitten by this! Can’t they all just get along…

I suppose we could whitelist assembly name patterns. In the released version everything is ilmerged anyway. Quite how people can recommend “assemblies aren’t scanned” is beyond me. Breaking reflection isn’t cool…

Or put self register assemblies to scan …

here’s how I solved it. I think. https://gist.github.com/thefringeninja/f107e08182058b3defcb

I’ll be rage quitting life now

FindAttacher()();

That made my day.

I can feel better about all code I’ll write today. #trololol

you seriously owe me a new keyboard after reading this code.