AspNetCoreRateLimit Implementation - c#

Do any of you have implemented the AspNetCoreRateLimit for an API with the Entity Framework Core 2.2 version?
I was trying to do it but it has been giving me an error that it cannot find certain methods or classes. For example:
services.AddSingleton<IRateLimitConfiguration, CustomRateLimitConfiguration>();
services.AddInMemoryRateLimiting();
NOTE: Those in bold style are missing.

Related

Is .Net 6 also called .NetFramework version 6? and is it not compatible with .netcoreapp2.0?

We are trying to upgrade our .Net core 2.1 app to use .Net 6. I used tried to use the upgrade assistant here, https://dotnet.microsoft.com/en-us/platform/upgrade-assistant/tutorial/install-upgrade-assistant
We now get many errors but the one that is confusing me is the naming, Is .NetFramework,Version 6.0 the same a .Net 6? I thought framework was old stuff?
Also as you can see from the error example below, it seems that our current nuget packages are not compatible with the new code, if I have read that right. Should we have set the nuget packages to be .Net Standard 2.1 to get around this?
Ok so I should not have tried to use the upgrade assistant, that seems to be for framework relates code. Instead following steps here https://learn.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-5.0&tabs=visual-studio for each version. Not ideal as would like an easier solution, but at least it gives some guidelines.

OData Queries broke when upgrading to .net core 6

We have encountered an issue during the upgrade from .net framework to .net core related to OData queries. It seems to come from the combination of the following components:
ASP.NET Core 6.0.0
Microsoft.AspNetCore.OData 8.0.11
EntityFramework 6.4.4
The issue is related to $filter and $select clauses when the API methods is returning an IQueryable<T>.
The exception message is "Unable to create a constant value of type 'Microsoft.OData.Edm.IEdmModel'. Only primitive types or enumeration types are supported in this context.".
Has anyone experienced this issue and have a workaround for EF6? Otherwise I guess we have to go straight to EF Core.

How do you reference/import .NET Standard 2.0 types in a .NET Core 2.1 project?

I have a .NET standard 2.0 class library that i keep all my domain classes in (just POCOs no dependencies).
I have a .NET core 2.1 azure functions project also. In visual studio i added a project reference to the class library, but it doesn't recognize any of my namespaces and classes when I try to reference them.
I just created an azure function, I see nowhere .Net Core 2.1, currently there are two versions a V1 in .Net Framework and V2 .Net Standard as you can see on the screenshot below, otherwise I find this link that you might be interested in, there are people who have the same problem as you, and they recommend to update to .Net Core 2.2.
The link below:
https://github.com/Azure/azure-functions-templates/issues/829

TypeLoadException Could not load type 'WebConfigurationManager' when calling .Net Framework Library via Web API Core app

I have a Web API application created using .Net Core 2.1. A controller from within this web application calls a Business Layer Class library that I also developed using .Net Core 2.1. So far so good...
The .Net Core Business Class Library references a commonly used .Net Framework 4.6.1 Class Library that we have also developed. This library is primarily used to communicate with Azure service bus queues.
As a result this commonly used .Net Framework Class Library in turn references and makes use of the Microsoft .Net Framework Assembly, Microsoft.ServiceBus as shown in the line of code below.
MessagingFactory messagingFactory = MessagingFactory.CreateFromConnectionString(configValue);
As you can see the line of code above that is within our commonly used .Net Framework Class Library passes a string value (i.e. configValue) to a static method that exists within the Microsoft.ServiceBus assembly.
However, whenever the line of code above executes I get the following Error:
An unhandled exception occurred while processing the request.
TypeLoadException: Could not load type
'System.Web.Configuration.WebConfigurationManager' from assembly
'System.Web, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'.
Out of interest I added in the following line of code which I get the same error:
string configValue = WebConfigurationManager.AppSettings["connectionString"];
Clearly, the issue is that the System.Web .Net Framework assembly isn't loaded.
However, given that the web application is .Net Core then how can I make this web application load the underlying .Net Framework assembly that the commonly used library requires?
Solutions Considered - (Unsuitable)
I had a similar issue before which was easily solved by installing the necessary NuGet package but on this occasion I have not been able to find such a package.
Our team has another Web API application in .Net Framework which calls this commonly used class library without issue however this is not an option and we need to keep the current Web API application based on .Net Core.
I also considered having the commonly used library re-written as a .Net Standard 2.0 Class Library but this given the size of the library this would not be a realistic approach and it won't necessarily address the underlying issue.
Other Possible Solutions
Load a Web.config from within the .Net Core Web API application that contains a configSections section referencing the assembly System.Web. I tried this but it didn't work which I'm sure if I just didn't apply all steps necessary. Is this possible and if so any suggestions?
Is there an alternative way to load the .Net Framework assembly from within the .Net Core Web API?
Sacrifice using the commonly used library and find an alternative (sample) code base that provides similar functionality (i.e. make use of Microsoft.ServiceBus to work with our Azure queues) but that is either .Net Core or .Net Standard based. But similar to the .Net Standard solution above I am unsure how much functionality would need replicated and also unsure of a starting point. Thoughts?
Thanks!
I had the same issue and after investigating i found that my azure function app run time version is 2.0 ~ and according to documentation version 2 is .NET Core 2 and function app version 1.0 ~ is .NET Framework 4.7 . and my visual studio function app project have .NET Framework 4.6.1 . So, I just had to change my function app version to ~ 1.0 .
In a Nutshell
If you have visual studio function app in .NET Core 2.0 then only use function app version 2.0
If you have visual studio function app in .NET Framework 4.7 then only use function app version 1.0

Log4Net with .net core 2 and framework Wrapper

I'm prototyping a .net core 2 web application. I've been asked to use Log4Net for handling our logging, but I want to put it in a .net framework 4.6.1 wrapper project as to allow for changing out the internal logging systems without having to update all of the method calls throughout the site.
Everything that I've found so far is for doing one or the other. Wrapping the log4net in 4.6.1 or doing a direct reference to the .net core.
So far, my 2 main exceptions are "FileNotFoundException" for when I use it as a direct reference, or when I do the PackageReference in the Framework proejct files I get a "Logging is not compatible with netcoreapp2.0. Logging is framework 4.6.1.
First, I would recommend making your wrapper using .NET standard 1.3 as this is the currently .NET core version supported by log4net, plus, this would allow you to reference this wrapper in .NET core and .NET framework 4.6 and up.
Second, see: https://stackify.com/making-log4net-net-core-work/ for some more info on getting log4net working with .NET core.

Categories

Resources