Hi
I would like to use Spanner Emulator for integration tests but when I use it with C# I get CallInvoker is set error.
The below is step by step to produce the error also I am attaching the simple code I have written in C#.
```
// for some reason C# doesn't find the environment variable so setting it manually
Environment.SetEnvironmentVariable("SPANNER_EMULATOR_HOST", "localhost:9010");
string projectId = "project-local-emulator";
string instanceId = "test-instance";
var builder = new SpannerConnectionStringBuilder
{
DataSource = $"projects/{projectId}/instances/{instanceId}",
EmulatorDetection = EmulatorDetection.EmulatorOnly,
};
await using var connection = new SpannerConnection(builder);
string createStatement = $"CREATE DATABASE `test-db`";
var cmdcreate = connection.CreateDdlCommand(createStatement);
await cmdcreate.ExecuteNonQueryAsync();
```
System.InvalidOperationException: CallInvoker is set, contrary to use of EmulatorDetection.EmulatorOnly
System.InvalidOperationException
CallInvoker is set, contrary to use of EmulatorDetection.EmulatorOnly
at Google.Api.Gax.GaxPreconditions.CheckStateT1,T2,T3
at Google.Api.Gax.Grpc.ClientBuilderBase1.GetEmulatorEnvironment(IEnumerable1 requiredEmulatorEnvironmentVariables, IEnumerable1 allEmulatorEnvironmentVariables, Func2 environmentVariableProvider)
at Google.Cloud.Spanner.Admin.Database.V1.DatabaseAdminClientBuilder.MaybeCreateEmulatorClientBuilder()
at Google.Cloud.Spanner.Admin.Database.V1.DatabaseAdminClientBuilder.InterceptBuild(DatabaseAdminClient& client)
at Google.Cloud.Spanner.Admin.Database.V1.DatabaseAdminClientBuilder.Build()
at Google.Cloud.Spanner.Data.SpannerCommand.ExecutableCommand.ExecuteDdlAsync(CancellationToken cancellationToken)
at Google.Cloud.Spanner.Data.SpannerCommand.ExecutableCommand.ExecuteDdlAsync(CancellationToken cancellationToken)
Would appreciate your help, as the error above doesn't really tell much what is wrong!
Hmmm... that's definitely not what I'd expect. Will try to look into it this afternoon, but it may be Monday before I can get to it.
Okay, I've reproduced it with this code:
using Google.Api.Gax;
using Google.Cloud.Spanner.Data;
using System;
namespace Issue5362
{
class Program
{
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("SPANNER_EMULATOR_HOST", "localhost:9010");
var builder = new SpannerConnectionStringBuilder
{
DataSource = $"projects/xyz/instances/abc",
EmulatorDetection = EmulatorDetection.EmulatorOnly,
};
using var connection = new SpannerConnection(builder);
var command = connection.CreateDdlCommand("create database `test`");
command.ExecuteNonQuery();
}
}
}
I've an idea what's wrong... will just need to validate.
I've discovered the problem - it was simpler than I'd feared. We just need to get the change reviewed, and then I'll do another release. Unfortunately I can't think of a simple workaround for this in the meantime, other than performing the DDL manually with DatabaseAdminClient for the moment.
This is now fixed in source code - I'll work with the Spanner team to schedule a new release with the fix in.
This has now been released as part of the 3.3.0 set of libraries.
Thank you so much Jon Skeet, you are legend! I will give this a go and let you know if there is any issue. 馃檹
Most helpful comment
This has now been released as part of the 3.3.0 set of libraries.