Posts

Showing posts with the label dotnet

Avoid Multiple Cache Refreshes: The Double Check Approach

 In previous articles, we've stressed the importance of caching to enhance the performance of our applications. This time, we're discussing a small yet potent tip to further amplify the benefits derived from caching. A standard caching routine often looks like this: This code is 'functional' and can be regarded as the 'default' approach to caching. Here, we're fetching a value from the cache, and if it's missing, we generate it and store it for future requests. However, a problem arises when we deal with a high-traffic application, such as a .NET Core web application or API, which must handle many concurrent requests. Suppose multiple requests reach this code simultaneously, each finding that it needs to generate the value. In such a case, you'll experience "multiple" refreshes of the same value and several calls to SetValue. To prevent this, we can employ a mutual-exclusion (mutex) lock to restrict multiple threads from accessing the sam...

NET Core, Java and Open Source

We need to talk about it How open is .NET Core and C#? How does it compare to a platform like Java? Well... let's see. Disclaimer: The post is a resumed version with lots of links, so be prepared to read it in a DFS or BFS way :)  .NET Core In November 2014, The Microsoft team announced that " NET Core is Open Source " Included C# and Visual Basic compilers Visual F#   ASP.NET Core Entity Framework Core NET Core Framework   In 2015, Microsoft releases Visual Studio Code , a cross-platform multi-language IDE.  All these released under an Open Source license. The MIT License . NET Core runs in Windows, Linux, Mac and ARM-based systems (IoT) Docker support existing Java Originally made open source by Sun in 2006 Released under GPLv2 CE license . The CE clause allows it to be used in a more restrictive scenario.  Oracle has a different licensing schema for "Enterprise Java". While the OpenJDK is still safe (and should remain so) Ente...

JustMock and "Failed to initialize coreCLR" on RC2

Image
Unable to start the process. Failed to initialize CoreCLR, HRESULT: 0x80131500 I just installed ASP.NET Core RC2 and was able to get it working from the command line, on some new basic tests projects. But when I tried to do it from Visual Studio I got the following error.  If I tried to run "dotnet" in a console opened from Visual Studio, I would get the same error. So the issue was that something was off for the VS configuration/environment.  After verifying that "dotnet" was able to run perfectly everywhere else I took into the task of comparing the environment variables (dichotomically, of course). One particular variable made the difference: "JUSTMOCK_INSTANCE=XXXXX", so that lead me to notice that JustMock was interfering with it somehow.  So, if you use JustMock just turn it off for RC2 projects. (No need to uninstall it, just disable the profiler)

The uncatchable exceptions in WCF clients

Did you ever have a problem with a WCF client throwing exceptions you can't catch? If you have used WCF clients from Windows Phone, Silverlight or Xamarin.iOS, you might have noticed that it is not possible to create Synchronous or Task-Based operations; the functionality is reduced to the Event-based Asynchronous Pattern (EAP). That means that the way to call a WCF method and get the response is usually as follows: var client = new MyWCFClient(); client.DownloadDataCompleted += (sender, e) => { try { //accessing e.Result here might raise an exception in another //thread, that will not be captured by the 'catch' below. } catch(Exception ex) { } }; client.DownloadDataAsync(url); Our results are wrapped in an auto-generated class that inherits from  AsyncCompletedEventArgs , this class has a property  Error  of type  Exception , that will carry information about the error and a property  Result  with our expected return valu...