Where is ReducerContext?
I followed the demo at https://spacetimedb.com/docs/modules/c-sharp/quickstart and created a module using the command: spacetime init --lang csharp server.
However, following the tutorial, I couldn't find ReducerContext. I was able to create IReducerContext, but I have absolutely no idea how to implement it.
Since C# and Rust are the primary languages being offered at this stage, it would have been great to have sample projects or something similar. Is it possible that I'm just having trouble finding them?
I'm very excited to apply this to .NET MAUI, but it seems too difficult at this early stage.
By the way, the version of SpacetimeDB.Runtime I'm using is 1.0.1.
what...? It was only missing in 1.0.1; it existed in 1.0.0. Where did it go in 1.0.1?
This fix in another issue and it might help you click
Instead of posting scam links like this, go study or do something productive
Hi @honeyhead! What do you mean that it's missing? This works for me:
spacetime init --lang csharp my-test-project
cd my-test-project
spacetime build
ReducerContext is generated at build time.
So every SpaceTimeDB C# project has to live with IDE errors, like "The type or namespace name 'ReducerContext' could not be found (are you missing a using directive or an assembly reference?)CS0246"?
So every SpaceTimeDB C# project has to live with IDE errors, like "The type or namespace name 'ReducerContext' could not be found (are you missing a using directive or an assembly reference?)CS0246"?
No, that's not expected. VSCode generally resolves the reference properly. Do you want to share your module project?
@bfops it's literally this: https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/tree/master/examples~/quickstart-chat/server
Here is my local copy: https://github.com/dotnetCarpenter/firetime/tree/fc942e3bbcc488aa3320f12ebb01a189ca65b1dd/server
Using:
dotnet --list-sdks
8.0.408 [/usr/share/dotnet/sdk]
9.0.203 [/usr/share/dotnet/sdk]
spacetime --version
spacetime Path: /home/dotnet/.local/share/spacetime/bin/1.1.0/spacetimedb-cli
Commit:
spacetimedb tool version 1.1.0; spacetimedb-lib version 1.1.0;
code --version
1.99.3
17baf841131aa23349f217ca7c570c76ee87b957
x64
With ms-dotnettools.csharp vscode extension
Version 2.72.34
Last Updated 2025-04-21, 14:49:03
and wasi-experimental installed.
┌──(dotnet㉿kali)-[~/projects/playground/firetime/server] (main)
└─$ dotnet workload list
Workload version: 8.0.408
Installed Workload Id Installation Source
----------------------------------------------
wasi-experimental SDK 8.0.400
Use `dotnet workload search` to find additional workloads to install.
@dotnetCarpenter interesting.. I'm not able to reproduce it on my machine and VScode, with all the same versions. We'll have to look into it more.
Does your explorer view list SpcaetimeDB.BSATN.Codegen and SpacetimeDB.Codegen?
Can you attach a screenshot of where you're getting this error? Is it in intellisense?
@bfops strangely enough, I don't get the errors after I have restarted my system. They were showing up in the Problems pane. Perhaps it was a language server issue. I also don't have the same explorer view as you have made a screen shot of. Which extension are you using?
I got the following installed: 1 af4jm.vscode-m3u 2 alexcvzz.vscode-sqlite 3 astro-build.astro-vscode 4 be5invis.toml 5 bierner.markdown-mermaid 6 bradlc.vscode-tailwindcss 7 chakrounanas.turbo-console-log 8 chpl-hpe.chapel-vscode 9 devtanc.tab-hero 10 devzstudio.emoji-snippets 11 eamodio.gitlens 12 editorconfig.editorconfig 13 esbenp.prettier-vscode 14 fabiospampinato.vscode-js-beautify 15 fernandoescolar.vscode-solution-explorer 16 github.vscode-pull-request-github 17 grapecity.gc-excelviewer 18 haskell.haskell 19 jock.svg 20 justusadam.language-haskell 21 llvm-vs-code-extensions.vscode-clangd 22 mads-hartmann.bash-ide-vscode 23 modular-mojotools.vscode-mojo 24 mrmlnc.vscode-json5 25 ms-dotnettools.csharp 26 ms-dotnettools.vscode-dotnet-runtime 27 ms-python.debugpy 28 ms-python.python 29 ms-python.vscode-pylance 30 ms-toolsai.jupyter 31 ms-toolsai.jupyter-keymap 32 ms-toolsai.jupyter-renderers 33 ms-toolsai.vscode-jupyter-cell-tags 34 ms-toolsai.vscode-jupyter-slideshow 35 ms-vscode-remote.remote-wsl 36 ms-vscode.cmake-tools 37 ms-vscode.cpptools 38 ms-vscode.live-server 39 ms-vscode.makefile-tools 40 ms-vsliveshare.vsliveshare 41 nwolverson.ide-purescript 42 nwolverson.language-purescript 43 qassimfarid.ejs-language-support 44 redhat.vscode-xml 45 rpinski.shebang-snippets 46 sjhuangx.vscode-scheme 47 stkb.rewrap 48 streetsidesoftware.code-spell-checker 49 timonwong.shellcheck 50 twxs.cmake 51 tyriar.sort-lines 52 v8-torque.vscode-torque 53 wayou.vscode-todo-highlight 54 yzhang.markdown-all-in-one 55 zhuangtongfa.material-theme
Hi @honeyhead! What do you mean that it's missing? This works for me:
spacetime init --lang csharp my-test-project cd my-test-project spacetime build
ReducerContextis generated at build time.
At the time, I saw version 1.0.1 available via NuGet in Visual Studio 2022, so I downloaded it. However, as I mentioned in my initial question, ReducerContext was not implemented.
spacetime init --lang csharp my-test-project
cd my-test-project
spacetime build
It works if you follow the method you mentioned. However, I did not use spacetime init because I wanted to integrate it into an existing project as a module, and the packages were already available on NuGet.
Also, I misunderstood the issue. It wasn’t really a problem with versions 1.0.0 or 1.0.1. When you run spacetime init and build, the following packages are installed:
- SpacetimeDB.BSATN.Codegen
- SpacetimeDB.Codegen
- SpacetimeDB.Runtime
I think I resolved the issue by manually installing some of these packages, especially Runtime, rather than it being a version-related problem between 1.0.0 and 1.0.1.
Once you install these three packages, you’ll be able to use ReducerContext. So, if you're installing via NuGet, just make sure to include those three packages.
Since it's a module, using spacetime init is definitely the more convenient way to get started. However, there may be others like me who find the packages on NuGet and try installing them directly—only to get confused. So I think it would be helpful if the tutorial also mentioned that, in the case of installing via NuGet, those three packages need to be included.
I ran spacetime init and spacetime build, so I guess my issue was related to language server picking up everything but ReducerContext.
It would be good to add spacetime build to https://spacetimedb.com/docs/modules/c-sharp/quickstart since I did not do that until I read this issue.
@bfops strangely enough, I don't get the errors after I have restarted my system. They were showing up in the Problems pane. Perhaps it was a language server issue. I also don't have the same explorer view as you have made a screen shot of. Which extension are you using?
I'm glad it's working now. As far as I know, the Explorer view is built in. Do you have it under View -> Open View -> Explorer?
I ran
spacetime initandspacetime build, so I guess my issue was related to language server picking up everything butReducerContext.It would be good to add
spacetime buildto https://spacetimedb.com/docs/modules/c-sharp/quickstart since I did not do that until I read this issue.
You shouldn't need to run spacetime build - it's run as part of spacetime publish.
Hi @honeyhead! What do you mean that it's missing? This works for me: spacetime init --lang csharp my-test-project cd my-test-project spacetime build
ReducerContextis generated at build time.At the time, I saw version 1.0.1 available via NuGet in Visual Studio 2022, so I downloaded it. However, as I mentioned in my initial question, ReducerContext was not implemented.
spacetime init --lang csharp my-test-project cd my-test-project spacetime buildIt works if you follow the method you mentioned. However, I did not use spacetime init because I wanted to integrate it into an existing project as a module, and the packages were already available on NuGet.
Also, I misunderstood the issue. It wasn’t really a problem with versions 1.0.0 or 1.0.1. When you run spacetime init and build, the following packages are installed:
- SpacetimeDB.BSATN.Codegen
- SpacetimeDB.Codegen
- SpacetimeDB.Runtime
I think I resolved the issue by manually installing some of these packages, especially Runtime, rather than it being a version-related problem between 1.0.0 and 1.0.1.
Once you install these three packages, you’ll be able to use ReducerContext. So, if you're installing via NuGet, just make sure to include those three packages.
Since it's a module, using spacetime init is definitely the more convenient way to get started. However, there may be others like me who find the packages on NuGet and try installing them directly—only to get confused. So I think it would be helpful if the tutorial also mentioned that, in the case of installing via NuGet, those three packages need to be included.
Ah that makes sense. I think SpacetimeDB.Runtime is the only required one - that package should include the other ones automatically.