Xbap (ClickOnce): The underlying connection was closed: An unexpected error occurred on a send


Last week after deploying to one of one of the internal environments, we got the following error on the installation of an xbap application

An exception occurred while downloading the manifest. Following failure messages were detected:

+ Downloading https://<url>/app.xbap did not succeed.

+ The underlying connection was closed: An unexpected error occurred on a send.

+ Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

+ An existing connection was forcibly closed by the remote host

It turned out that the IT group had disabled TLS 1.0 and 1.1. After enabling those protocols, the xbap was operating as expected

Categories: Uncategorized

Performance tip – Caching expiry in web applications


Caching data that rarely change can give you a big performance boost especially if it takes time to fetch and/or calculate that data. In .NET 4.0, Microsoft introduced the .NET Memory Cache which is a thread safe cache that can be used Windows and Web applications. For more information about the MemoryCache class you can visit https://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache(v=vs.110).aspx

While I was doing a load test for web application for one of my clients, I noticed that the Queued Requests performance counter goes up every five minutes. By using a code profiler, it showed that there were many calls to refresh some of the cached data. Taking a closer look at the code below, if user 1 executing line (value = service.GetStreets();) while the other users are checking if value is cached, there is a potential of thousands of requests to fetch the same data especially if that data is frequently used.

We were using a CacheWrapper that applies a cache policy based on the cache name. With the CacheWrapper we can write the code to cache the Street Streets as follows:


public List<Street> GetStreets()
{

var value = CacheWrapper.Get(CacheNames.Streets) as List<Street>;

if (value == null)
{

    value = service.GetStreet();
    CacheWrapper.Set(CacheNames.Streets, value);

}

return value;

}

My first approach was to use a lock and double check the value


bool StreetsDataInitialized = false;
Object StreetsLock = new Object();

public List<Street> GetStreets()
{

var value = CacheWrapper.Get(CacheNames.Streets) as List<Street>;

if (value == null)
{
StreetsDataInitialized = false;

lock (StreetsLock)
 {
 if (StreetsDataInitialized)
 {
    return CacheWrapper.Get(CacheNames.Streets) as List<Street>;
 }

 value = service.GetStreets();
 CacheWrapper.Set(CacheNames.Streets, value);
 StreetsDataInitialized = true;

}

}

return value;

}

But there were many values that need to be cached and refreshed and I didn’t want to create two variables per cached value. I came up with a more generic way to achieve my goal. I started with the CacheLock Class

 public class CacheLock
  {
     public bool Initialized { get; set; }
     public object LockObject = new object();

 }

I used the ConcurrentDictionary to store the locks. I also created a generic GetOrSetCacheValue function which gets or creates a CacheLock for each cached data and invoke “function” if the data is not cached.


Public class CacheableLookupProvider
{
private static ConcurrentDictionary<string, CacheLock> LockDictionary = new ConcurrentDictionary<string, CacheLock>();
private readonly IStreetsService service;

Public CacheableStreetsProvider(IStreetsService service)
{
    this.service = service;
}

 private T GetOrSetCachedValue<T>(string cacheName, Func<T> function) where T : class
 {
    var value = CacheWrapper.Get(cacheName) as T;
    if (value == null)
     {
       var lockObject = LockDictionary.GetOrAdd(cacheName, new CacheLock());
       lockObject.Initialized = false;
      
      lock (lockObject.LockObject)
       {
         if (lockObject.Initialized)
         {
           return CacheWrapper.Get(cacheName) as T;
         }
         value = function();
         CacheWrapper.Set(cacheName, value);
         lockObject.Initialized = true;
       }
    }
    return value;
 }

 public List<Street> GetStreets ()
 {
    return GetOrSetCachedValue(CacheNames.Streets, () => service.GetStreets());
 }

 public List<Province> GetProvinces ()
 {
   return GetOrSetCachedValue(CacheNames.Provinces, () => service. GetProvinces());
 }

}

Categories: asp.net Tags: , , ,

Install TFS2015 ctp with basic configurations


Categories: Uncategorized Tags:

TFS2015 CTP and VS2015 CTP6 are available for download


In case you missed the news, Visual Studio 2015 CTP 6 and TFS 2015 CTP are available for download. The following link contains the release notes and the bits http://www.visualstudio.com/en-us/downloads/visual-studio-2015-ctp-vs

Remember not to install CTP products on your production machines. They are for testing purposes and are not supported

Categories: Uncategorized Tags: ,

Test Controller machine is running out of space


Yesterday, the c: drive on the Test Controller machine was running out of space while doing load testing. There few solutions to this problem

Solution1

Delete files and folders under %localappdata%\VSEQT\QTController

Solution 2

If you are still running out of space, consider moving the Test Controller VSEQT folder to another drive

  • Go to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE
  • Open QTController.exe.config and QTController64.exe.config
  • Add to the appSettings section the following line

    <add key=”WorkingDirectory” value=”D:\Test Controller Data”/>

    The WorkingDirectory entry is the base directory for staging/temporary files, overrides Windows default Application Data Directory

  • Restart the ‘Visual Studio Test Controller”


  • Run a Load Test



Categories: ALM Tags: , ,

Free Course: Introduction to Mobile App Development


Interested in learning something new during the holidays? Here is a free course from the Microsoft Virtual Academy

http://www.microsoftvirtualacademy.com/training-courses/introduction-to-mobile-app-development?prid=ca_DevMVP_AAA

Categories: Uncategorized

Replace JavaScript serializer in Kendo controls with NewtonSoft


I have been doing code optimization for an ASP MVC 5 application that uses the Telerik Kendo controls. Some of the search results may return 7000 records in this project. After I had replaced the serializer, it took 30% less time to load the search results page.

 

The ASP MVC Helpers for Kendo controls by default use the System.Web.Script.Serialization.JavaScriptSerializer which is slow compared to the NewtonSoft Json serializer. Telerik made it easy to replace the default serializer.

Steps:

  • Created a class that implements IJavaScriptSerializer and implement the Serialize method.
    public class CustomKendoJsonSerializer : IJavaScriptSerializer
    {
       public string Serialize(object value)
       {
          return JsonConvert.SerializeObject(value); //use the serializer you want  here
       }
     }
    
  • Create a class that implements JavaScriptInitializer and implement the CreateSerializer method
    
    public class CustomKendoInitializer : JavaScriptInitializer
    
    {
    
    public override IJavaScriptSerializer CreateSerializer()
    
    {
    
    return new CustomKendoJsonSerializer ();
    
    }
    
    }
    
    
  • In the Application_Start event in the Global.asax file, register the new serializer
Kendo.Mvc.Infrastructure.DI.Current.Register<IJavaScriptInitializer>(() => new CustomKendoInitializer());
Categories: .NET, asp.net, C# Tags: , ,
Follow

Get every new post delivered to your Inbox.

Join 442 other followers