0

EDIT

I'm using Blazor WASM project. I'm trying to create an Indexed DB to my project with TG.Blazor.IndexedDB NuGet Package. I create Startup.cs in my project. I have a few error in Program.cs & Startup.cs.

Error CS0246 The type or namespace name 'IComponentsApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)

Starup.cs

using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using TG.Blazor.IndexedDB;


 namespace WebApplication
{
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddIndexedDB(dbStore =>
        {
            dbStore.DbName = "TheFactory";
            dbStore.Version = 1;

            dbStore.Stores.Add(new StoreSchema
            {
                Name = "Employees",
                PrimaryKey = new IndexSpec { Name = "id", KeyPath = "id", Auto = true },
                Indexes = new List<IndexSpec>
                {
                    new IndexSpec{Name="firstName", KeyPath = "firstName", Auto=false},
                    new IndexSpec{Name="lastName", KeyPath = "lastName", Auto=false}

                }
            });
            dbStore.Stores.Add(new StoreSchema
            {
                Name = "Outbox",
                PrimaryKey = new IndexSpec { Auto = true }
            });
        });
    }
//error here 
    public void Configure(IComponentsApplicationBuilder app)
    {
        app.AddComponent<App>("app");
    }
}
 }

Error CS1061 'WebAssemblyHost' does not contain a definition for 'Run' and no accessible extension method 'Run' accepting a first argument of type 'WebAssemblyHost' could be found (are you missing a using directive or an assembly reference?)

Error CS0103 The name 'BlazorWebAssemblyHost' does not exist in the current context

Program.cs

using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using TG.Blazor.IndexedDB;


 namespace WebApplication
{
public class Program
{
    public static async Task Main(string[] args)
    {
        var builder = WebAssemblyHostBuilder.CreateDefault(args);
        builder.RootComponents.Add<App>("#app");

        builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

        await builder.Build().RunAsync();
       
        // error at Run()
        CreateHostBuilder(args).Build().Run();
    }
    public static WebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
        //error at BlazorWebAssemblyHost
       BlazorWebAssemblyHost.CreateDefaultBuilder()
           .UseBlazorStartup<Startup>();
}
}

What I have tried:

Tg.Blazor.IndexedDB

Missing startup.cs program.cs .Net Core Razor

Hani
  • 21
  • 1
  • 12
  • Try `WebHost` instead. – Jevon Kendon Apr 12 '21 at 04:46
  • @JevonKendon I have tried & still error – Hani Apr 12 '21 at 04:53
  • Not sure. I just ran ` dotnet new blazorserver -o BlazorApp --no-https` to generate a new blazor project. `Host` is found. I might suggest you start there, and update the generated code. – Jevon Kendon Apr 12 '21 at 05:03
  • From https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/create – Jevon Kendon Apr 12 '21 at 05:04
  • You have __2x__ `.Build().RunAsync()`. That can't be right. – H H Apr 12 '21 at 05:58
  • Seems like you merged 2 examples, or that you are confusing Server.Program.cs and Client.Program.cs . – H H Apr 12 '21 at 05:59
  • @HenkHolterman Before this, `CreateHostBuilder(args).Build().Run();` but error ` Error CS1061 'WebAssemblyHost' does not contain a definition for 'Run' and no accessible extension method 'Run' accepting a first argument of type 'WebAssemblyHost' could be found (are you missing a using directive or an assembly reference?)` – Hani Apr 12 '21 at 06:53
  • @HenkHolterman Im not sure but I saw a few blazor project that use Startup.cs & Program.cs. Im trying to create Indexeddb in blazor using NuGet Package but having problem here in the Program.cs – Hani Apr 12 '21 at 06:58
  • "I saw a few blazor project" - Blazor comes in two varieties with very different Program/Startup logic. – H H Apr 12 '21 at 07:08
  • You're pulling code from Blazor Server and trying to ram it into Web Assembly. `WebAssemblyHostBuilder` is the host builder for WASM. `Host` is in ` Microsoft.Extensions.Hosting`, but I'm pretty sure it specific to Server. What's in Startup that you want to run? – MrC aka Shaun Curtis Apr 12 '21 at 17:02
  • @MrCakaShaunCurtis I have edit & insert the Program.cs & Startup.cs code – Hani Apr 13 '21 at 01:02

1 Answers1

1

This is the Splash page for Reshiru.Blazor.IndexDB.

It's DEPRECIATED, out of date, and stale. In my book that means don't go near it.

enter image description here

MrC aka Shaun Curtis
  • 19,075
  • 3
  • 13
  • 31