Tuesday, April 14, 2020
Upgrade to .NET Core 3.1 - Migration warning CS0618 'RazorViewAttribute' is obsolete
This error is simple, you can even find the answer is SO. It's caused by one of your nugets, you only need to update it to the latest version. Finding the offending nuget is another story. Hopefully you don't have too many nugets to update.
Sunday, April 12, 2020
Upgrade to .NET Core 3.1
Last week I had the task of upgrading a project written in .NET Core 2.1 to .NET Core 3.1. I'll be posting solutions to the errors I came across. But first, I'll show important sections of my Startup.cs and Program.cs:
I'll start with Program.cs:
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
host.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseLamar()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).ConfigureLogging(builder =>
{
...
builder.AddApplicationInsights();
});
On to the file Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureContainer(ServiceRegistry services)
{
services.Configure<CookiePolicyOptions>(options =>
{
...
});
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Con
services.AddMediatR();
services.AddAutoMapper();
services.AddSession();
...
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(typeof(AzureAuthorizationFilter));
...
options.UseModelBinding();
});
services.AddRazorPages().SetCompatibilityVersion(CompatibilityVersion.Latest).AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
.AddTypedRouting()
.AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
services.AddAuthorization();
services.Configure<RazorViewEngineOptions>(options => {
...
});
services.AddSignalR();
services.Scan(scan =>
{
scan.TheCallingAssembly();
...
scan.WithDefaultConventions();
});
services.For<IPrincipal>().Use(x => Thread.CurrentPrincipal);
...
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseSession();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
"default",
"{controller=Home}/{action=Index}/{id?}");
endpoints.MapHub<NotificationHub>("/pushHub");
});
}
}
I'll start with Program.cs:
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
host.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseLamar()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).ConfigureLogging(builder =>
{
...
builder.AddApplicationInsights();
});
On to the file Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureContainer(ServiceRegistry services)
{
services.Configure<CookiePolicyOptions>(options =>
{
...
});
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Con
services.AddMediatR();
services.AddAutoMapper();
services.AddSession();
...
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(typeof(AzureAuthorizationFilter));
...
options.UseModelBinding();
});
services.AddRazorPages().SetCompatibilityVersion(CompatibilityVersion.Latest).AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
.AddTypedRouting()
.AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
services.AddAuthorization();
services.Configure<RazorViewEngineOptions>(options => {
...
});
services.AddSignalR();
services.Scan(scan =>
{
scan.TheCallingAssembly();
...
scan.WithDefaultConventions();
});
services.For<IPrincipal>().Use(x => Thread.CurrentPrincipal);
...
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseSession();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
"default",
"{controller=Home}/{action=Index}/{id?}");
endpoints.MapHub<NotificationHub>("/pushHub");
});
}
}
Tuesday, May 16, 2017
Cannot import the following key file. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate
I got an error when compiling a project in TeamCity. This particular project had assemblies signed. TeamCity threw an error that said:
Cannot import the following key file. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_FFA0xxxxx
The fix to this problem is quite simple:
1) Open the Developer Command Prompt for VS 2017
2) Type:
sn -i "c:\path to your pfx\file.pfx" VS_KEY_xxxxxx
where the VS_KEY is what Team City said
Cannot import the following key file. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_FFA0xxxxx
The fix to this problem is quite simple:
1) Open the Developer Command Prompt for VS 2017
2) Type:
sn -i "c:\path to your pfx\file.pfx" VS_KEY_xxxxxx
where the VS_KEY is what Team City said
Sunday, April 9, 2017
ASP.NET Identity - Invalid token error
I was generating a code for a user to reset her password. However, this error came up when trying to reset the password. I had 2 problems:
1) The token was being generated in a computer that was not where the token was actually used. I read in SO that the token is tied to a key in the web.config, so either the web.config -keep in mind that ASP.NET has a hierarchy of web.config files, so there's more than 1- needs to match or you need to generate and use the token in the same server.
2) The token contained the plus sign (+). When using it, the server encoded it as a space, so you need to do string.Replace(" ", "+")
1) The token was being generated in a computer that was not where the token was actually used. I read in SO that the token is tied to a key in the web.config, so either the web.config -keep in mind that ASP.NET has a hierarchy of web.config files, so there's more than 1- needs to match or you need to generate and use the token in the same server.
2) The token contained the plus sign (+). When using it, the server encoded it as a space, so you need to do string.Replace(" ", "+")
Sunday, January 22, 2017
Web deploy error when publishing to azure: String larger than expected
This happened to me while trying to deploy 1 files (a dll) to azure. I couldn't find any answers on SO or other sites. The solution was to deploy all files as opposed to deploying only 1 file
Sunday, December 11, 2016
Azure returning a 404 for woff files
This is actually a configuration error, as described here
http://www.codepal.co.uk/show/WOFF_files_return_404_in_Azure_Web_Sites
The solution was to add the following to the web.config:
<system.webServer>
<staticContent>
<mimeMap fileExtension="woff" mimeType="application/font-woff" />
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
</staticContent>
http://www.codepal.co.uk/show/WOFF_files_return_404_in_Azure_Web_Sites
The solution was to add the following to the web.config:
<system.webServer>
<staticContent>
<mimeMap fileExtension="woff" mimeType="application/font-woff" />
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
</staticContent>
Thursday, September 15, 2016
OpenVPN not changing my IP address
When I installed the OpenVPN client and connected to a VPN it changed my IP address correctly. However, subsequent times it didn't change it. It turned out I had to run the application as an administrator, and that was it.
Subscribe to:
Posts (Atom)