GeKu
GeKu

Reputation: 63

.NET MAUI Blazor Hybrid images not rendering

I simply tried to add an image and show it in navigation drawer, which led to not rendering the image and simple showing the placeholder of an not found image. So investigated further and found out, the issue is still existent in a raw project using it's default images like "favicon.png" or "dotnet_bot.svg".

So first here my setup:

I use my project with target for Windows Desktop, Android (API 33/34), Web.

The project templates i used for creating my projects, also with same issues, are

As mentioned at the beginning, i just used almost the raw templated project. Only modifications: i added a ""-tag in the home.razor page like that:

@page "/"

<h1>Hello, world!</h1>

<img src="../../wwwroot/favicon.png" />
Welcome to your new app.
<img src="../../Resources/Images/dotnet_bot.svg" />

the images are added by default to the project, no custom resources. The paths are made up from auto suggestions in VS and hovering over the paths will show a small thumbnail in VS, validating a valid path. The build actions for the first is Content and for the second is MauiImage. Running these apps is working fine in ".NET MAUI Blazor-App" templated projects with images marked as "Content" under wwwroot but is resulting in following outputs for my focused ".NET MAUI Blazor Hybrid and Web App" templated projects:

Target Android Target Windows Desktop Target Web

EDIT: I tried multiple things but can only get images been rendered on the second template-projects. So here some additional information about my failing attempt at "NET MAUI Blazor Hybrid and Web App" project:

The web project is missing a wwwroot directory by template... possibly this is a reason? Images are not in output this way... bug or my fault? enter image description here

May be any body has an idea on what stupid thing i am missing... it is just a picture isn't it...?! Thanks!

Upvotes: 0

Views: 591

Answers (1)

Zippy
Zippy

Reputation: 11

I'm also on Visual Studio 17.12.0 Preview 2.1 which currently has the design that appears to be coming with .Net 9 (as that's what this project template generates, although it appears to be happy to be rolled back to .Net 8)

Visual Studio Project Template:

Visual Studio Project Template

That generates the following projects.

Visual Studio Projects:

Visual Studio Projects

The fun begins because when images etc are in a Razor Class Library (RCL) the page will no longer accept the usual syntax, instead the following is required.

.razor page syntax:

.razor page syntax

The full details of how static assets are found is here BlazorWebView static assets

i.e. _content/{PACKAGE ID}/{PATH AND FILE NAME}

where {PACKAGE ID} will be the project name unless otherwise set in the Project Properties.

Project Properties - set PACKAGE ID:

Project Properties - set PACKAGE ID

Upvotes: 1

Related Questions