3

I have a Blazor Server .Net 8 web application. I right-click on the Blazor sever project and select "Add" then ".Net Aspire Orchestrator Support".

This added the two Projects (AppHost, and Service Defaults) to my solution. The AppHost project is selected as the start-up project. When I run the app in Debug mode it fails and I am getting the below-attached error.

Any idea what is wrong? It seems it's trying to convert a string to a boolean.

When I debug my app normally without using Aspire, I use IIS Express in Visual Studio

If it helps this is the full error msg

System.Text.Json.JsonException
  HResult=0x80131500
  Message=The JSON value could not be converted to System.Nullable`1[System.Boolean]. Path: $.profiles.DptBlazor.dotnetRunMessages | LineNumber: 27 | BytePositionInLine: 33.
  Source=System.Text.Json
  StackTrace:
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Stream utf8Json)
   at Aspire.Hosting.LaunchProfileExtensions.GetLaunchSettings(IProjectMetadata projectMetadata)
   at Aspire.Hosting.LaunchProfileExtensions.GetLaunchSettings(ProjectResource projectResource)
   at Aspire.Hosting.LaunchProfileExtensions.TrySelectLaunchProfileFromEnvironment(ProjectResource projectResource, String& launchProfileName)
   at Aspire.Hosting.LaunchProfileExtensions.SelectLaunchProfileName(ProjectResource projectResource)
   at Aspire.Hosting.LaunchProfileExtensions.GetEffectiveLaunchProfile(ProjectResource projectResource, Boolean throwIfNotFound)
   at Aspire.Hosting.ProjectResourceBuilderExtensions.WithProjectDefaults(IResourceBuilder`1 builder, Boolean excludeLaunchProfile, String launchProfileName)
   at Aspire.Hosting.ProjectResourceBuilderExtensions.AddProject[TProject](IDistributedApplicationBuilder builder, String name)
   at Program.<Main>$(String[] args) in C:\inetpub\wwwroot\MyApp\Dpt.AppHost\Program.cs:line 3

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
InvalidOperationException: Cannot get the value of a token type 'String' as a boolean.

enter image description here

enter image description here

Im using IIS Express when I run it without Aspire and it works fine. But when I try and use Aspire i get the error

My launchSettings.json is below, im using Windows Auth:

  {
  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iis": {
      "applicationUrl": "http://localhost/DptBlazor",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IIS",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

After cleaning up launchSettings.son I got it to run a bit more, but now I get an odd error.

enter image description here enter image description here enter image description here enter image description here

enter image description here enter image description here

My launching settings file is below:

{
  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:61105",
      "sslPort": 44392
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IIS",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost/DptBlazor",
      "dotnetRunMessages": true
    },
    "DptBlazor": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "dotnetRunMessages": true
    }
  }
}

Below is the code im using to get the Windows Authentication User Name, which seems to come back blank:

private readonly AuthenticationStateProvider authProvider;

       var authenticationStateTask = await authProvider.GetAuthenticationStateAsync();

   var user = authenticationStateTask.User;

   if (user.Identity.IsAuthenticated)
   {
       return user.Identity.Name.Split('\\')[1]; ;
   }
13
  • 1
    Have you added 'builder.AddServiceDefaults();' into the startup.cs of Blazor Server Application ? Commented May 28, 2024 at 13:49
  • 1
    Normally this error occurs when JSON is generated with "" as value instead of the null element. Commented May 28, 2024 at 13:55
  • 1
    Yes, that's okay. I believe it has to do with the launcher profile. Do you have any specific launcherProfile settings defined into your webapp "dptBlazor" ? if yes, then in AppHost project's startup.cs at line 3 change it to "builder.AddProject<Projects.DptBlazor>("dptBlazor", "launchProfileName")" Commented May 29, 2024 at 20:53
  • 1
    I am adding my sample application setting. I have launcherProfile with "http" and "https" names. My AppHost looks like this.builder.AddProject<Projects.AspireAppTest_Web>("webfrontend", "http") //.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development") .WithOtlpExporter() .WithExternalHttpEndpoints() .WithReference(apiService); Commented May 29, 2024 at 20:56
  • 1
    We are close to solve this. Have you added "builder.AddProject<Projects.DptBlazor>("dptBlazor", "IIS Express")" This will link the profile and application url. Commented May 30, 2024 at 19:32

1 Answer 1

3

This solution works for a Blazor Server application running with "IIS Express" profile and .Net Aspire Orchestrator Support added later on. This will generate an error message something like below when you first run your Aspire.host project with "https" profile.

enter image description here

To resolve this error, you need to update launchSettings.json file of your original Blazor server project. Go to BlazorServerApp.UI project > Properties folder > expand it and open launchSettings.json file. It will look like something below.

{
  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:61105",
      "sslPort": 44392
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "BlazorServerApp.UI": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "dotnetRunMessages": "true" 
    }
  }
}

Change the line from "dotnetRunMessages" : "true" to "dotnetRunMessages": true. This is the bug from Asire framework. This will start your project but will show you an empty or "None" endpoints on Aspire Dashboard. See user's question screenshot above.

Add below two lines into your "IIS Express" profile.

 "applicationUrl": "https://localhost/blazorserverapp",
 "dotnetRunMessages": true

This will fixed the problem and start showing you your newly entered endpoints into Aspire Dashboard. The final launchSettings.json will look like below.

{
  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:61105",
      "sslPort": 44392
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      //below lines added manually
    //"applicationUrl": "https://localhost:44392",
      "applicationUrl": "https://localhost/blazorserverapp",
      "dotnetRunMessages": true
    },
    "BlazorServerApp.UI": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      //Changed below line manually from "true" to true
      "dotnetRunMessages": true
    }
  }
}

In Aspire.Host, I have to changed back to builder.AddProject<Projects.BlazorServerApp_UI>("blazorserverapp-ui"); without mentioning the "IIS Express".

If you are getting "failed to start" error on Aspire Dashboard then follow below two steps.

  1. Close Solution and Close Visual Studio
  2. Delete ".vs" folder from solution path
  3. Reopen VS and your solution.
  4. Run the Aspire.Host

It should start and Aspire Dashboard will start showing below Endpoint registered.

enter image description here

Let me know this works for you or not. I have to update my packages to the latest version for everything to workout well. Make sure you are not using Visual Studio Preview version.

Sign up to request clarification or add additional context in comments.

7 Comments

This is amazing, you are a star! I get an error when I try and Multiple Start Up Projects when Debugging and having solution not only load the .AspHost but also my Blazor app. See attached screen shot I added for the error.
I am using Aspire.Host as my startup project. I launch my BlazorServerApp by clicking on Endpoint URL from Aspire Dashboard. I am not sure why you are start both of the projects as multiple startup projects.
Ahh I see what you mean, I dont need it to be a multi startup. But I have hit another issue when I click the web link in Aspire, the Windows Authentication does not seem to work, see attached screen shot and my lanchSettings.json Thanks ever so much for your support
Try right click on it and open it in incognito mode. It might be because of the browser cache. I have my window authentication working with this.
I tried incognito, still no joy. I have posted above what I have on my page of how I get the Windows Authentication User Name, it always assumes the user is not authenticated.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.