Skip to content

Null Reference Exception #541

@udhaytgn

Description

@udhaytgn

This is a fantastic library. Thank you for the effort. Generally well built.

I'm encountering a null reference exception when trying the load a page with the diagram in my MAUI Blazor Hybrid application. Can you please help. Here is what the page looks like

@page "/diagramtest"
@using Blazor.Diagrams
@using Blazor.Diagrams.Components
@using Blazor.Diagrams.Core.Models
@using Blazor.Diagrams.Core.Geometry
@using Blazor.Diagrams.Core.Options

@if (Diagram != null)
{
    <CascadingValue Value="Diagram" IsFixed="true">
        <DiagramCanvas Diagram="Diagram" class="diagram-container" />
    </CascadingValue>
}
else
{
    <p>Loading diagram...</p>
}

@code {
    private BlazorDiagram? Diagram;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            var options = new BlazorDiagramOptions
            {
                Links =
                {
                    DefaultRouter = new NormalRouter(),
                    DefaultPathGenerator = new StraightPathGenerator()
                }
            };

            Diagram = new BlazorDiagram(options);

            // Create a test node
            var node = new NodeModel(new Point(100, 100)) { Title = "Test Node" };
            Diagram.Nodes.Add(node);

            StateHasChanged();
        }
    }
}

When trying to access this page, I get the message "Loading diagram..." and then the null reference exception pops up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions