Posts

Step by step migration of ASP.NET Core 2.2 to 3.1

In order to upgrade/migrate asp.net core version to 3.1 following steps to be perform. Download and install Visual Studio 2019 version 16.4 or higher. Download and install .NET Core 3.1  https://dotnet.microsoft.com/download/dotnet-core/3.1 Upgrade the projects of solution to .NET Core 3.1 , because ASP.NET Core 3.1 requires it. Update existing Nuget packages to a version compatible with ASP.NET Core 3.1 in each project Use IHost interface from a IHostBuilder instead of building and running a IWebHost from a IWebHostBuilder in Program.cs public static IHostBuilder CreateWebHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseKestrel() .UseSerilog() .UseStartup<Startup>(); }) Change AddMvc method has been replaced by AddControllers in Startup.cs of each projects. In Startup.cs, UseMvc method to b

Log exception to file in c# .net core application explained

In production environment when any bug gets reported at that time as developer wants to get the exception details of bug to resolve the issue on high priority. In some case there might be situation where exception is not logged in table but developer wants to check the bug immediately. for that purpose we need to write the exception details including stack trace of bug in file. To implement this easily i am going to demonstrate the implementation of custom logging in file as below. First we need to construct the exception and logger method in custom logger class as shown below. public class CustomLogger { public static List<string> ConstructExceptionDetails(Exception ex,string FunctionName) { return new List<string>() { $"{DateTime.Now} - {FunctionName}", $"Exception: {ex.Message}", $"StackTrace: {ex.StackTrace}", $"InnerException: {ex.InnerEx

Error The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) while WMI script execution [resolved]

WMI(Windows Management Instrumentation) is powerful and flexible tool when used correctly, it can deliver the best and most important information about your computers, servers and notebooks. But when connecting to the remote machine fails then following error can be occurred. The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) To resolve error you need to cross verify the below checklist to resolve the above error. Verity that "Windows Management Instrumentation" is running in the remote machine and set it to auto start after restart. Verify that you are entered correct host name or IP Address you need to check that "Remote Procedure Call (RPC)" is running in the remote machine and set it to auto start after restart. you need to check that "TCP/IP NetBIOS Helper" is running in the remote machine and set it to auto start after restart. Need to enable Windows Management Instrumentation (WMI) rule in windows firewall in order to a

All about the IEnumerable VS IQueryable in c#

In Linq or entity framework, we use IEnumerable and IQueryable for data manipulation or query data. IEnumerable is inherited by IQueryable , Hence IQueryable has all the features of IEnumerable and except this, it has its own features and benefits. Both have its own importance to query data and data manipulation in different situations in the application. we can go through with both the features and take the advantage of both the features to boost the LINQ Query performance. As per the need of application at some stage  IEnumerable is useful and some stage in the application  IQueryable is useful. Lets discuss about its use and features now. IEnumerable Features: IEnumerable exists in System.Collections Namespace. IEnumerable can move forward only over a collection, it can’t move backward and between the items. IEnumerable is best to query data from in-memory collections like List, Array etc. While query data from database, IEnumerable execute select query on server side,

clone a generic list in C# using extension method

In practical situation you need to clone of object so that change in cloned object will not affect the original one. If you need a cloned list with the same capacity you need to do some extra stuff with your user type. I came up with this easy solution using ICloneable interface in your custom type class. The first step you need to implement the ICloneable interface in your class like below. public class MyClassDto : ICloneable { public Int64 Id { get; set; } public string Time { get; set; } public int user{ get; set; } public object Clone() { return new MyClassDto{ Date = this.Date, Id = this.Id, user = this.user}; } } after that you need to add extension method in common class so that you can use it everywhere you want. public static class Extensions { public static List<T> Clone<T>(this List<T> listToClone) where T : ICloneable { return listToClone.Select(item

Source Code Beautifier And Format Source Code For Blogger and Websites

Source Code Beautifier And Formatter For Blogger and Websites, Format Source Code , Format Source code for blog or blogging & website, Online line source code formatter tool, blogger code format tool, Format source code for blog-spot,Insert formatted source code How to format source code for blogger & website :   You can format your source code for blogger & website in easy three steps.. 1) Paste your source code into "Paste Here Your Source Code" Text-area. 2) Choose appropriate options from "formatting options" and click Format Source Code button.. 3) See preview of formatted source code if it's fine then copy from "Copy Formatted Source Code" text-area otherwise repeat step 2  This source code formatter allow you to format code like JavaScript, HTML, CSS, C#, PHP, ASP.net, VB.Net, Visual Basic, DOT.net, ASP & many other languages.  It does not add unnecessary tags into formatted code, It use only two t

Dependency injection in ASP.NET Core MVC controller explained step by step

ASP.NET Core MVC controllers should request their dependencies explicitly via their constructors. In some instances, individual controller actions may require a service, and it may not make sense to request at the controller level. In this case, you can also choose to inject a service as a parameter on the action method. With ASP.NET 5 MVC6, we get a feature called dependency injection baked right into the framework for us. Dependency injection is a technique that follows the Dependency Inversion Principle, allowing for applications to be composed of loosely coupled modules. ASP.NET Core has built-in support for dependency injection, which makes applications easier to test and maintain. ASP.NET Core's built-in support for constructor-based dependency injection extends to MVC controllers. By simply adding a service type to your controller as a constructor parameter, ASP.NET Core will attempt to resolve that type using its built in service container. Services are typically, b