zHaytam / SmartBreadcrumbs

A utility library for ASP.NET Core (both MVC and Razor Pages) websites to easily add and customize breadcrumbs.
https://blog.zhaytam.com/2018/06/24/asp-net-core-using-smartbreadcrumbs/
MIT License
161 stars 77 forks source link

Net 6 - Error with GetTypes with new template #97

Closed maurobernal closed 2 years ago

maurobernal commented 2 years ago

En Net 5.0, en StartUp.cs

 public class Startup
    {
       ...
           public void ConfigureServices(IServiceCollection services)
        {
            services.AddBreadcrumbs(GetType().Assembly);
          }
}

En Net 6.0 in Program.cs

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddBreadcrumbs(GetType().Assembly);

var app = builder.Build();
app.Run();

I have this error with GetType():

An object reference is required for the non-static field, method, or property 'object.GetType()'

matteoaldera commented 2 years ago

Hi, this is because in net6.0 template Program.cs is intended as static initializer, than you cannot use GetType() because isn't a static method. Try instead typeof(Program).

maurobernal commented 2 years ago

With builder.Services.AddBreadcrumbs(typeof(Program)); i have this error: "cannot convert of System.Type to System.Reflection.Assembly" i also tried this builder.Services.AddBreadcrumbs(builder.GetType().Assembly);

maurobernal commented 2 years ago

That's how it worked builder.Services.AddBreadcrumbs(typeof(Program).Assembly);

matteoaldera commented 2 years ago

Yes, I realized that I have not explained very well. My intent was to substitute GetType() with typeof(Program), not to use instead of GetType().Assembly.