Hey all,
I'm looking at using componentize-dotnet and am having trouble understanding how to use types such as variant, option or result in C#. I'm not sure what I need to implement or what, if anything, is generated for me to use or how to use it.
Are there any examples of how this should be done?
Ok, I'm sure I'm just doing something wrong but at this point I'm tempted to say result doesn't work properly with C#.
So far as I can see, if a function is defined in wit to return a result, the C# code is incorrectly expected to return the type the result is parameterized by; so if the wit defines the function as returning result<int, string>, the C# code expects int, not result<int, string>.
All right, if I understand correctly, if you're implementing an exported function that returns a result, there are generated bindings that call the function you implement, and it is they that return Ok or Err based on whether your implementation throws an exception.
So the behavior I described before, where you just need to return the value that would get wrapped in an Ok, makes sense if you know that.
I'd have to think about it more, but I feel like I'd rather handle returning the Ok/Err myself.
As it is, the function I have to implement in this case has a misleading signature that doesn't match the wit.
Also, it has to throw an exception for Err, and my understanding is exceptions are not great for performance.
You may be interested in this PR and the option it added.
That does look interesting, thank you!
I'm not sure how I should use it, though. I was thinking maybe adding <Wit Update="gen-host.wit" World="gen-host" feature="with_wit_results=false" />
to the .csproj might do the trick, but it doesn't seem t.
@James Sturtevant do you know the answer to this?
I don't think we pipe through extra setting to witbindgen yet. @godotdot Could you open an issue?
Consider it done @James Sturtevant https://github.com/bytecodealliance/componentize-dotnet/issues/66
Thanks! I am AFK for a couple days but will take a look soon
Cool, thank you!
@godotdot this should be resolved in https://www.nuget.org/packages/ByteCodeAlliance.Componentize.DotNet.Wasm.SDK v0.6.0.
Last updated: Apr 08 2025 at 20:03 UTC