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

I am running into two issues when I try to use the EventStore.ClientAPI.Embedded nuget package. I am guessing that they are related.

  1. When I don’t also add the EventStore.ClientAPI nuget package, I get the following error:

System.TypeInitializationException was unhandled

_HResult=-2146233036

_message=The type initializer for ‘EventStore.Core.Messaging.MessageHierarchy’ threw an exception.

HResult=-2146233036

IsTransient=false

Message=The type initializer for ‘EventStore.Core.Messaging.MessageHierarchy’ threw an exception.

Source=EventStore.ClientAPI.Embedded

TypeName=EventStore.Core.Messaging.MessageHierarchy

StackTrace:

at EventStore.Core.Bus.InMemoryBus…ctor(String name, Boolean watchSlowMsg, Nullable`1 slowMsgThreshold)

at EventStore.Core.ClusterVNode…ctor(TFChunkDb db, ClusterVNodeSettings vNodeSettings, IGossipSeedSource gossipSeedSource, ISubsystem[] subsystems)

at EventStore.ClientAPI.Embedded.EmbeddedVNodeBuilder.op_Implicit(EmbeddedVNodeBuilder builder)

at Runner.Program.Main(String[] args) in c:\Proofs\Proof.EventStore.AzureCloudService\Runner\Program.cs:line 23

at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

InnerException: System.Reflection.ReflectionTypeLoadException

_HResult=-2146232830

_message=Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

HResult=-2146232830

IsTransient=false

Message=Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Source=mscorlib

StackTrace:

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__31`3.MoveNext()

at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()

at EventStore.Core.Messaging.MessageHierarchy…cctor()

InnerException:

  1. When I do add the reference, I am able to run the server, but I get a “Error during execution of command: Unexpected TCP package: BadRequest…” message when using the EventStore.TestClient against it even though the ping command works. Here is the console output from the EventStore.TestClient:

ES VERSION: 3.0.0.0 (master/51cef1881b1c5ab5e3962fb61bffac1dc99ec506, Wed, 17 Sep 2014 16:42:34 +01

OS: Windows (Microsoft Windows NT 6.2.9200.0)

RUNTIME: .NET 4.0.30319.34209 (64-bit)

GC: 3 GENERATIONS

LOGS: C:\Projects\Atomic\EventStore\EventStore.Server\EventStore-OSS-Win-v3.0.0\es-logs

HELP: False ()
VERSION: False ()

LOG: ()

CONFIG: ()

DEFINES: ()

WHAT IF: False ()

IP: 127.0.0.1 (Command Line)

TCP PORT: 100 (Command Line)

HTTP PORT: 2113 ()

TIMEOUT: -1 ()

READ WINDOW: 2000 ()

WRITE WINDOW: 2000 ()

PING WINDOW: 2000 ()

FORCE: False ()

COMMAND: ()

ping
Segments count: 1, buffers count: 512, should be when full: 512

[06180,05,16:45:48.946] Processing command: ping.

[06180,06,16:45:48.980] [127.0.0.1:100]: PING…

[06180,03,16:45:49.038] [127.0.0.1:100]: PONG!

[06180,05,16:45:49.038] Command exited with code 0.

WRFL 1 1000

[06180,05,16:45:56.050] Processing command: WRFL 1 1000.

[06180,05,16:45:57.051] Error during execution of command: Unexpected TCP package: BadRequest…

[06180,05,16:45:57.051] Command exited with code 1.

Here is what my program looks like:

The first issue is known (fixed in the next release), second one will need some investigation.

James

When is the next release?

Ryan

How are you wiring up your embedded eventstore?

<- duh

what happens when you communicate over the internal ip

ping doesn’t work. WRFL doesn’t work. but different error…

Here is the console output:

Segments count: 1, buffers count: 512, should be when full: 512
[07140,01,20:18:05.157]
ES VERSION: 3.0.0.0 (master/51cef1881b1c5ab5e3962fb61bffac1dc99ec506, Wed, 17 Sep 2014 16:42:34 +0100)
OS: Windows (Microsoft Windows NT 6.2.9200.0)
RUNTIME: .NET 4.0.30319.34209 (64-bit)
GC: 3 GENERATIONS
LOGS: C:\Projects\Atomic\EventStore\EventStore.Server\EventStore-OSS-Win-v3.0.0\es-logs

HELP: False ()
VERSION: False ()
LOG: ()
CONFIG: ()
DEFINES: ()
WHAT IF: False ()
IP: 127.0.0.1 ()
TCP PORT: 2000 (Command Line)
HTTP PORT: 2001 (Command Line)
TIMEOUT: -1 ()
READ WINDOW: 2000 ()
WRITE WINDOW: 2000 ()
PING WINDOW: 2000 ()
FORCE: False ()
COMMAND: ()

ping
Segments count: 1, buffers count: 512, should be when full: 512
[07140,13,20:18:07.560] Processing command: ping.
[07140,03,20:18:08.576] TcpTypedConnection: connection to [127.0.0.1:2000, L, {6da7e9d2-e565-4790-bf59-2d33a44fa19e}] failed. Error: ConnectionRefused.
[07140,13,20:18:08.576] Error during execution of command: Connection was closed prematurely…
[07140,13,20:18:08.576] Command exited with code 1.

WRFL 1 1000
[07140,13,20:18:14.071] Processing command: WRFL 1 1000.
[07140,03,20:18:15.088] TcpTypedConnection: connection to [127.0.0.1:2000, L, {851d440a-353e-4d96-aabe-be2caa609527}] failed. Error: ConnectionRefused.
[07140,13,20:18:15.088] Error during execution of command: Connection was closed prematurely…
[07140,13,20:18:15.088] Command exited with code 1.

That looks like the log from test client? What does the server say?

Changed it to run on disk, but not seeing a logs directory or log files.

That might be a nice feature. Plus a way to hook into logging directly (i.e .WithLogger(new MyLogger() )

The console output contains:

Starting
Running
Segments count: 1, buffers count: 512, should be when full: 512

The first two lines are from my console app.

Last line was from ES.

What did you set the path to?

C:\temp\estest

oh, and I am seeing writer.chk, chunk-000000.000000, etc in that path.

Whats missing is the

            string logsDirectory =
Path.GetFullPath(options.Log.IsNotEmptyString() ? options.Log :
GetLogsDirectory(options));
            LogManager.Init(componentName, logsDirectory);

that is in ProgramBase.

Much of the stuff with certificates and setup as well as some other
things still need to be moved to embedded client if people want to use
it for hosting their own nodes that other things talk to as well. e.g.
        protected static X509Certificate2
LoadCertificateFromStore(string certificateStoreLocation, string
certificateStoreName, string certificateSubjectName, string
certificateThumbprint)

Cheers,

Greg

You’ll likely also need the NLog configuration (for now, that may be changing, see https://github.com/EventStore/EventStore/issues/255)

Cheers,

James

Finally had a chance to look further into this.

Here is what I found:

  1. I needed a reference to protobuf-net.dll

  2. I needed to setup the logmanager properly.(see code below).

  3. I needed a copy of NLog.config

Here is what my code looks like:

private static void Main(string[] args)
{
Console.WriteLine(“Starting”);

LogManager.SetLogFactory(s => new NLogger(s));
LogManager.Init(“Runner”, @“c:\temp\eslogs”);
var logger = LogManager.GetLoggerFor();
logger.Info(“Starting”);

ClusterVNode node = EmbeddedVNodeBuilder.AsSingleNode()
.OnDefaultEndpoints()
.RunInMemory()
.RunProjections(ProjectionsMode.All);

var are = new AutoResetEvent(false);
node.NodeStatusChanged += (sender, change) =>
{
if (change.NewVNodeState == VNodeState.Master ||
change.NewVNodeState == VNodeState.Slave)
{
are.Set();
}
};
node.Start();
are.WaitOne();

Console.WriteLine(“Started”);
Console.ReadLine();
Console.WriteLine(“Stopping”);
node.Stop();
LogManager.Finish();
Console.WriteLine(“Stopped”);
Console.ReadLine();
}

@all should we internalize the protobuf reference?

Greg

I thought we did already? I’ve run into this as well and this is how I solved it.

@Ryan is this with nugget package or?

with nuget package

I just realized I misspoke slightly about this issue. The problem is that you are trying to use the embedded client + TCP which would then require protobuf. The ClientAPI had protobuf internalized (as of 1.0.1) but the embedded client did not.

It does now just not released yet