elringus / bootsharp

Compile C# solution into single-file ES module with auto-generated JavaScript bindings and type definitions
https://sharp.elringus.com
MIT License
673 stars 36 forks source link

JSON from WebAssembly #159

Closed Dexus closed 3 months ago

Dexus commented 3 months ago

I am just reaching my limits, I have

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

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
        <Nullable>enable</Nullable>
        <!-- Not embedding binaries to source module reduces build size by ~30%. -->
        <BootsharpEmbedBinaries>false</BootsharpEmbedBinaries>
        <!-- Disabling non-essential .NET features reduces minimal build size by ~35%. -->
        <BootsharpAggressiveTrimming>false</BootsharpAggressiveTrimming>
        <!-- Enable multi-threaded mode to run CPU-intensive tasks on worker threads. -->
        <WasmEnableThreads>true</WasmEnableThreads>
    </PropertyGroup>

and try to use System.Text.Json.JsonSerializer.Serialize


    [System.Serializable]
    public class RequestSecurity
    {
        public string Signature { get; set; }
        public string CodeString { get; set; }
        public DateTime? CreationTime { get; set; }
        public string Nonce { get; set; }
    }

RequestSecurity p = new RequestSecurity
            {
                Signature = jsonResponse2Signature,
                CodeString = jsonResponse2,
                CreationTime = DateTime.Now,
                Nonce = HmacHash256.RandomString(32)
            };
string json = System.Text.Json.JsonSerializer.Serialize<RequestSecurity>(p);         

but the json string is always {} I'm not sure how I can prevent this.

My C# experiens is now 1 week... sorry for that.

elringus commented 3 months ago

Not sure how is this related to Bootsharp. I'd suggest looking for System.Text.Json docs/tutorials.