Skip to content

CSharp quickstart does not compile #2647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BinarySpike opened this issue Apr 19, 2025 · 7 comments
Open

CSharp quickstart does not compile #2647

BinarySpike opened this issue Apr 19, 2025 · 7 comments

Comments

@BinarySpike
Copy link

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

🤔

@bfops
Copy link
Collaborator

bfops commented Apr 21, 2025

I'm not able to reproduce this issue. The not null check should be sufficient here 🤔

Can you share your StdbModule.csproj and spacetime --version?

@ScherrerMichael
Copy link

ScherrerMichael commented Apr 28, 2025

Hello, I am also facing this issue following the quickstart.

spacetime --version output:
spacetimedb tool version 1.1.0; spacetimedb-lib version 1.1.0;

csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8</TargetFramework>
    <RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="SpacetimeDB.Runtime" Version="1.1.0" />
  </ItemGroup>

</Project>

using VScode:

Version: 1.99.3 (user setup)
Commit: 17baf841131aa23349f217ca7c570c76ee87b957
Date: 2025-04-15T23:18:46.076Z
Electron: 34.3.2
ElectronBuildId: 11161073
Chromium: 132.0.6834.210
Node.js: 20.18.3
V8: 13.2.152.41-electron.0
OS: Windows_NT x64 10.0.19045

@bfops
Copy link
Collaborator

bfops commented Apr 28, 2025

Thanks @ScherrerMichael! It's the same code that's causing an error? What build command are you using?

@ScherrerMichael
Copy link

No problem!
Yes it is the exact same code, everything else works fine except for handling of the null-able type reference user, despite enabling the Nullable cs project directive. I even tried adding the #nullable enable annotation to no success.

I used spacetime publish <server-name> and spacetime publish --project-path <server-path> <server-name> as well.

@bfops
Copy link
Collaborator

bfops commented Apr 29, 2025

@ScherrerMichael what does your dotnet --info say? I think we will probably just fix this with some more explicit null-casting, but it would be good to know why is happening for some people and not others.

@ScherrerMichael
Copy link

This is my output for dotnet --info:

.NET SDK:
 Version:           8.0.408
 Commit:            e6663e9b3d
 Workload version:  8.0.400-manifests.5ac61b9b
 MSBuild version:   17.11.26+2b19be476

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.408\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
 [wasi-experimental]
   Installation Source: SDK 8.0.400
   Manifest Version:    8.0.15/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.current\8.0.15\WorkloadManifest.json
   Install Type:        FileBased


Host:
  Version:      9.0.4
  Architecture: x64
  Commit:       f57e6dc747

.NET SDKs installed:
  5.0.402 [C:\Program Files\dotnet\sdk]
  8.0.311 [C:\Program Files\dotnet\sdk]
  8.0.408 [C:\Program Files\dotnet\sdk]
  9.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not set

global.json file:
  C:\Users\Michael\Desktop\SpaceMMO\server\global.json

Learn more:
  https://aka.ms/dotnet/info
  Not set

global.json file:
  C:\Users\Michael\Desktop\SpaceMMO\server\global.json

Learn more:
  https://aka.ms/dotnet/info

  Not set

global.json file:
  C:\Users\Michael\Desktop\SpaceMMO\server\global.json

Learn more:
  Not set

global.json file:
  Not set
  Not set

global.json file:
  C:\Users\Michael\Desktop\SpaceMMO\server\global.json

Learn more:
  Not set

global.json file:
  C:\Users\Michael\Desktop\SpaceMMO\server\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
global.json file:
  C:\Users\Michael\Desktop\SpaceMMO\server\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
  https://aka.ms/dotnet/download

@bfops
Copy link
Collaborator

bfops commented Apr 30, 2025

Thank you! That all seems reasonable.. I guess we'll just update the quickstart and call it a day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants