Skip to content

CSharp quickstart does not compile #2647

Open
@BinarySpike

Description

@BinarySpike

On https://spacetimedb.com/docs/modules/c-sharp/quickstart

The below code does not compile:

[Reducer]
public static void SetName(ReducerContext ctx, string name)
{
    name = ValidateName(name);

    var user = ctx.Db.user.Identity.Find(ctx.Sender);
    if (user is not null)
    {
        user.Name = name;
        ctx.Db.user.Identity.Update(user);
    }
}

I get the errors:

...server\Lib.cs(30,12): error CS1061: 'Module.User?' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument 
of type 'Module.User?' could be found (are you missing a using directive or an assembly reference?) [...\server\StdbModule.csproj]

...server\Lib.cs(31,35): error CS1503: Argument 1: cannot convert from 'Module.User?' to 'Module.User' [...\server\StdbModule.csproj]

This is due to .Find(...) returning a Module.User? (nullable) and both user.Name and Identity.Update(...) expecting a Module.User (not nullable)

This is also the case for the following functions ClientConnected and ClientDisconnected

🤔

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions