添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Started a new Blazor WebAssembly project (Windows 10, Visual Studio 2019), trying to get a simple list via HttpClient from the server side.

Error:

00755c3a:0xa3a0 Uncaught (in promise) RuntimeError: memory access out of bounds
    at malloc (<anonymous>:wasm-function[359]:0xa3a0)
    at monoeg_malloc (<anonymous>:wasm-function[161]:0x3c71)
    at stack_frag_new (<anonymous>:wasm-function[2019]:0x59758)
    at add_frag (<anonymous>:wasm-function[1430]:0x3ccf2)
    at interp_exec_method (<anonymous>:wasm-function[1120]:0x2f609)
    at interp_runtime_invoke (<anonymous>:wasm-function[5655]:0xf7391)
    at mono_jit_runtime_invoke (<anonymous>:wasm-function[5109]:0xddb3d)
    at do_runtime_invoke (<anonymous>:wasm-function[1410]:0x3ba85)
    at mono_runtime_try_invoke (<anonymous>:wasm-function[418]:0xcfdb)
at mono_runtime_invoke (<anonymous>:wasm-function[1610]:0x44b39)

Server side (this returns properly):

    [HttpGet]
    public async Task<IEnumerable<UserDetailsRM>> Get()
        var users = await UserService.GetUsers();
        return users;

client side: doesn't render anything despite getting results back.

<div class="userListWrapper">
        @if (Users != null)
            <table class="table table-borderless" style="font-size:12px; font-family:arial; height: 
                500px; display:block;   overflow-y:scroll">
                <thead>
                        <th scope="col">Profile</th>
                        <th scope="col">Full Name</th>
                        <th scope="col">Gender</th>
                        <th scope="col">Age</th>
                </thead>
                @foreach (var user in Users)
                    <tbody class="scrollableTable" style="border-radius:15px;">
                        <tr class="userRow" >
                            <td><img src="@user.ProfileImageUrl" style="width:30px;border- 
                             radius:30px" /></td>
                            <td>@user.FullName</td>
                            <td>@user.Gender</td>
                            <td>@user.Age</td>
                    </tbody>
            </table>
@code{
private IEnumerable<UserDetailsRM> Users;
string LoggedEmail;
string UserId;
string UserActionMessage = "No Logged User";
string Wanted = "";
protected async override Task OnInitializedAsync()
    Users = await Http.GetFromJsonAsync<IEnumerable<UserDetailsRM>>("user");

client project file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <RazorLangVersion>3.0</RazorLangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="5.0.0-preview.6.20312.15" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rc.2.20475.17" PrivateAssets="all" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\Domain\Domain.csproj" />
  </ItemGroup>
</Project>

server project file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="3.2.1" />
    <PackageReference Include="NetTopologySuite" Version="2.1.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\DataAccess\DataAccess.csproj" />
    <ProjectReference Include="..\Client\TeamAppManager.Client.csproj" />
  </ItemGroup>
</Project>

Would appreciate any help. Thanks.

Edit: Models:

public class UserDetailsRM :  IIntEntity
    public int Id { get; set; }
    public int UserDetailsId { get; set; }
    public string UserId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime Birthdate { get; set; }
    public int UserGenderOptionId { get; set; }
    private string gender;
    public string Gender
        get { return gender; }
            if (value == "1")
                gender = "Male";
            else if (value == "2")
                gender = "Female";
                gender = "Other";
    public string FullName
            return $"{FirstName} {LastName}";
            FullName = value;
    public int Age
            var today = DateTime.Today;
            var age = today.Year - Birthdate.Year;
            if (Birthdate.Date > today.AddYears(-age)) age--;
            return age;
    public string ProfileImageUrl { get; set; }
                Can you post the code of the relevant model(s) and  UserService.GetUsers. You may have  a circular reference issue...
– enet
                Oct 22, 2020 at 17:39
                This model worked on a Blazor Server app as it is, but not on WASM. This indeed was the problem. Thanks!
– Zion Hai
                Oct 22, 2020 at 18:41
                In my case, I was assigned the value to a different variable in the set method and encountered such an error, removing the set method worked. But, why this happens? what if we need such get set methods?
– venu
                Apr 13, 2021 at 6:00
                I think the issue here is that the set accessor is trying to assign the value to the property name instead of a backing field. I guess there won't be any issue with this( need verification), but the source of the get accessor won't be the backing field. Again, I'm only guessing. I might be wrong...perhaps the framework won't accept that...
– enet
                Apr 13, 2021 at 6:20
                The issue there is its setting FullName to itself which sets it to self ad infinitium - so basically its an infinite recursion and it runs out of memory. Quite ironically this is what causes stack overflow errors :) but thanks for this question as it shows me i have must have done the same somewhere in my code with a recent change as I am also getting this error and yes it would have happened anywhere the code is run - even on blazor server
– Matthew Joughin
                Jun 2, 2021 at 9:22
  • 5.0.0-rc.2.20475.17
  • <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="5.0.0-preview.6.20312.15" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rc.2.20475.17" PrivateAssets="all" />
    

    For 3.2.1

    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
    

    For 5.0 rc2

    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rc.2.20475.17" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rc.2.20475.17" PrivateAssets="all" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.Net.Http.Json" Version="5.0.0-rc.2.20475.5" />
    

    As WASM runs in your browser you should clear the applications cache as well, between dll changes.

    The reason I tried updating in the first place was to solve the problem. I reverted back to 3.2.1, nothing changes. Problem remains. – Zion Hai Oct 22, 2020 at 17:59

    Adding to @enet answer for future similar cases, it requires to define local variable like this, otherwise it is a circular reference which eventually lead to out of memory issue:

        private string _Name
        public string Name
             //...
             return this._Name;
             this._Name = value;
             //...
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.