Retry and fault handling in C# .NET

Sometimes you need to implement some sort of retry logic if an error occurs in a c# program.

Existing libraries for retry and fault handling:
Polly
http://www.thepollyproject.org/

CircuitBreaker.Net
https://github.com/alexandrnikitin/CircuitBreaker.Net

Read more about the related Circuit Breaker pattern:

CircuitBreaker
http://martinfowler.com/bliki/CircuitBreaker.html

Circuit Breaker Pattern
https://msdn.microsoft.com/en-us/library/dn589784.aspx

Error handling and policies in general:

https://en.wikipedia.org/wiki/Exception_handling#Restarts_separate_mechanism_from_policy

https://docs.microsoft.com/en-us/dotnet/standard/exceptions/

https://stackify.com/csharp-exception-handling-best-practices/

git – Having problems cloning a Azure DevOps repository in Visual Studio 2019 Community – Stack Overflow

Clearing the cached credentials from Credential Manager. And then try again.Go to Credential Manager–> Windows Credentials–> Generic Credentials–>Remove all Git related credentials.

Source: git – Having problems cloning a Azure DevOps repository in Visual Studio 2019 Community – Stack Overflow

Error Handling with Angular 8 – Tips and Best Practices

Handling errors properly is essential in building a robust application in Angular. Error handlers provide an opportunity to present friendly information to the user and collect important data for development. In today’s age of advanced front-end websites, it’s more important than ever to have an effective client-side solution for error handling.

An application that does not handle errors gracefully leaves its users confused and frustrated when the app suddenly breaks without explanation. Handling these errors correctly across an application greatly improves user experience. Collected data from the error handling can inform the development team about important issues that slipped past testing. This is why monitoring tools like Rollbar are so important.

In this article, we will compare several solutions for error handling in Angular apps. First, we will describe the traditional approaches using ErrorHandler and HttpClient. Then, we will show you a better solution using HttpInterceptor. We’ll also show you how to use this interceptor to monitor and track errors centrally in Rollbar.

 

Source: Error Handling with Angular 8 – Tips and Best Practices

Solution for .NET error: The type ‘HttpResponseMessage’ exists in both ‘System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ and ‘System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

Got this error when building a .NET framework (version 4.6.1) solution containing multiple projects:

The type 'HttpResponseMessage' exists in both 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

My solution:
Install System.Net.Http version 4.0.0 as nuget package to the “failing project”.

Added this to the “failing” project app.config file:

<assemblyBinding>
<!-- other dependentAssembly bindings here -->
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>

Updated the “failing” projects .csproj file like this:
Removed this line or similar for System.Net.Http:

<!--<Reference Include="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />-->

Added “hintpath” with projects relative path to the nuget packages.
In my example its 3 level up and then down (..\..\..) you might need to adjust to your projects folderstructure.

<Reference Include="System.Net.Http, Version=4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.Net.Http.4.0.0\ref\dotnet\System.Net.Http.dll</HintPath>
</Reference>

Voila.

Fixing Webstorm cant debug in Chrome error: “Please ensure that the browser was started successfully with remote debugging port opened”

Error message in Jetbrains Webstorm:

Waiting for connection to localhost:59066. Please ensure that the browser was started successfully with remote debugging port opened. Port cannot be opened if Chrome having the same User Data Directory is already launched.

Can be fixed by installing the “jetbrains ide” chrome extension and make sure the above settings checkbox is active “Use JetBrains IDE support extension…”

c# – sgen.exe fails during build – Stack Overflow

After adding a new 3rd party reference to a project and then building for Release configuration I got this error (not present when in debug build):
Error Could not load file or assembly ‘x’ or one of its dependencies. The system cannot find the file specified. SGEN  

Here is a solution that worked for me:

If you are having this problem while building your VS.NET project in Release mode here is the solution: Go to the project properties and click on the Build tab and set the value of the “Generate Serialization Assembly” dropdown to “Off”. Sgen.exe is “The XML Serializer Generator creates an XML serialization assembly for types in a specified assembly in order to improve the startup performance of a XmlSerializer when it serializes or deserializes objects of the specified types.” (MSDN)

Source: c# – sgen.exe fails during build – Stack Overflow

EPiServer edit and admin not working after upgrade to EPiServer 11.8

I have upgraded a site from EPiServer 7.5 to 11.8.
When deploying the upgraded site to the test environment the edit and admin interface stopped working (the top episerver ui menu visible but lots of js errors and no “main edit window visible” and entire admin mode 404 not found).

The problem was related to some old config for “ProtectedAddons”, i just commented the below config in web.config on test server and the edit and admin mode works again.

(comment out/remove below from web.config)

<!--<virtualPathProviders>
<clear />
<add name="ProtectedAddons" virtualPath="~/epi/" physicalPath="[appDataPath]\Modules" type="EPiServer.Web.Hosting.VirtualPathNonUnifiedProvider, EPiServer.Framework.AspNet" />
</virtualPathProviders>-->

Inspiration for the solution came from here: Object reference error in initialization modules

change a .net 4.6.1 project to .net 4.7 failed – Stack Overflow

when I change the targetting from .net 4.6.1 to .net 4.7 . I get this error when build , but there is no project .json , how can I pass this? project cannot compile now. Severity Code Description Project File Line Suppression State Error ` Your project is not referencing the “.NETFramework,Version=v4.7” framework. Add a reference to “.NETFramework,Version=v4.7” in the “frameworks” section of your project.json, and then re-run NuGet restore.

Delete /bin and /obj and rebuild your solution.

 

Source: change a .net 4.6.1 project to .net 4.7 failed – Stack Overflow

asp.net mvc – razor views are not giving compile time error – Stack Overflow

Razor views are dynamically compiled by the ASP.NET runtime. If you want your views to be built at compile-time you could add the following option to your .csproj file:
<PropertyGroup>
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>

You may take a look at the this article for more details.

Source: asp.net mvc – razor views are not giving compile time error – Stack Overflow