Tuesday, July 22, 2014

Not able to uninstall .net assembly from GAC

Occasionally when we try to uninstall .net dll from GAC by pressing delete button, it will show the below error message.
Unable to uninstall: assembly is required by one or more applications

Solution 1 - Run in admin mode

The major reason could be the user don't have permission to delete the dll from GAC. If we run the windows folder explorer in administrator mode it might be uninstalled. How to run the windows explorer as in administer mode? We cannot right click and "Run as administrator" on any item to get an explorer window in admin mode. So we need to run the cmd in admin mode. and use the GACUtil.exe to remove the dll. 

Most of the cases it will get uninstalled. Else try the below link to and uninstall as admin .

Solution 2 - Installer problem. Edit registry

There is one more reason why we cannot uninstall from GAC. Sometimes the the assembly might have installed into GAC by installers and they will hold the reference so that we cannot uninstall from GAC. If this is the case we need to remove some registry entries present inside the below registry path.

[HKCU\Software\Microsoft\Installer\Assemblies\Global]
[HKLM\SOFTWARE\Classes\Installer\Assemblies\Global]

This is already reported to MSFT and more details can be found in below links.
http://support.microsoft.com/kb/873195
http://blogs.msdn.com/b/alanshi/archive/2003/12/10/42690.aspx

Last week when I was trying to run a sample which I got from internet, it was loading wrong Microsoft.Practices.Unity.dll. I could see that there is one Microsoft.Practices.Unity.dll of different version in the GAC. So thought of deleting it from GAC and it ended up in the above mentioned error.

Monday, July 14, 2014

Hosting ASP.Net MVC app in Windows 8 IIS 8 - HTTP Error 403.14 - Forbidden

Recently I was trying to run an ASP.Net MVC application in my new Windows 8 environment. When I run the application from visual studio, I got the below error.

HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.


It was silly as the Windows 8 by default don't support pre .Net 4.0 versions also we need enable programming support explicitly.

First We need to enable it in
Control panel -> Turn windows features -> .Net framework 3.5(includes .Net 2.0 and 3.0) in case the project is targeting older version.

Also we need to enable ASP.Net development support too. Go to  Control panel -> Turn windows features -> Internet Information Services-> World wide web services -> Application development features and enable ASP.Net 3.5 and 4.5 based on the project target.

http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-using-aspnet-35-and-aspnet-45

Tuesday, July 8, 2014

Why my Roslyn extension is not getting loaded?

Below is my experience when I started working with a Roslyn project which I got from my colleague. First thing

Is the Roslyn compiler enabled for the Visual Studio test instance?

Yes there is something called enabling Roslyn. As we know Roslyn is the new compiler. The Visual Studio can now support 2 compilers. Traditional and Roslyn. So how the Visual Studio knows, it needs to use Roslyn? 
The answer is the below command line argument which needs to be passed to Visual Studio process devenv.exe when its started.

/rootsuffix Roslyn

If we are building VSIX extension project, we can mention this command line argument in the project properties->debug tab. This will make sure the test Visual Studio instance will be using the Roslyn compiler.

If the visual studio test instance itself not starting when we run the extension project, make sure the below path is there in the Project properties->Debug -> Start external program text box.

<Drive>:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe

Is the VSIX extension actually loaded or there is any bug in my code?

First of all check whether the Visual studio test instance can start with Roslyn enabled. If yes, load a project in the test instance of Visual Studio. If so go back to parent Visual Studio where we write our extension code and look at Modules window.

Debug->Windows-Modules

If our assembly is listed there in indicate that the extension is loaded. Now we can go to next debugging step.

Why the VSIXManifest is copied to wrong Roslyn extensions folder

If we are not able to find our extension assembly in the modules window, it indicate that the Visual Studio is not able to locate our extension assembly. To understand this better we should understand how the Roslyn extension is working under the hood. When we press the run button on the Roslyn extension project from VS,

  • It is compiling the project and copying the dlls including the extension.VSIXManifest file to the below mentioned location
    • <Drive>:\Users\<name>\AppData\Local\Microsoft\VisualStudio\12.0Roslyn\Extensions
  • The above underlined folder name "12.0Roslyn" is controlled by a project property given below
    • <VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>
If the property hold a wrong value, it may copy the compiled vsix extension to wrong folder and the Roslyn extension will not take effect when we load Visual Studio test instance.

Why my VSIX extension files are not getting copied to Roslyn extension folder

Sometimes we will be having proper value in the <VSSDKTargetPlatformRegRootSuffix> tag. But still the files may not be copied. That will be due to improper values in the below project properties.

<IncludeAssemblyInVSIXContainer> true </IncludeAssemblyInVSIXContainer>  
<IncludeDebugSymbolsInVSIXContainer> false </IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>  false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>    true</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>    true </CopyOutputSymbolsToOutputDirectory>

Best solution is to remove all these properties so that it will take the default behavior and default will copy required dlls to extensions folder.

Can I change these VSIX project properties using the properties tab?

The answer is NO as the project properties tab don't have the UI to support these properties. There is already a bug raised to Microsoft.

Is there a real issue in my code?

If all these things are set properly and still our Roslyn VSIX extension is not working, there is something wrong in the code. Inspect the code for below scenarios.
  • Class level attributes.
  • The interfaces implemented 
  • Whether the SymbolKindsOfInterest property returns proper list?

More links


Happy debugging...

Tuesday, July 1, 2014

Philly.net - Code Camp 2014 - Day 2

This is continuation of my earlier post about day 1. I am following the same format of What I expected and What I got sections

Explaining, demonstrating and using the OpenStack.Net SDK By Don Schenck

What I expected

Cloud is really amazing when we think about how the internal system management software modules work together to provide on demand scaling. OpenStack gave me answer how it might be. Unfortunately I never had a chance to experiment it. So I thought there will be at least sometime dedicated for demonstrating how to setup a cloud using Open stack. Then about the .Net SDK which can be used to manage the cloud.

What I got

Unfortunately I was not able be there in the session from beginning. So when I entered in the hall, he was telling about the .Net SDK part. As of my expectation he did it well. But there was not much audience. Only 8 persons were there.

Beyond the basics - A Deep dive into the AngularJS works By Todd Snyder

What I expected

As per the name no basics. Only the internalsof how AngularJS works.

What I got

He started with SPA architecture and slowly explained the concepts of AngularJS such as Templates, Directives, Controllers , DataBinding, Modules etc...Then he showed in the PPT how certain things can be done such as databinding , $apply etc...It was not much interesting to me so went for brunch.

Entry level app development for Windows 8 By David Voyles

What I expected

I never planned this session. I just sit for this session because there was enough seats so that I can sit and have brunch. I really don't like to eat food by holding the plate in my hand. When I sit, I thought let me listen to something which I don't know also for any tips and tricks he may share from his experience.

What I got

It was demo time when I entered and he was showing great demos. He showed some stunning websites which are coded using HTML and Javascript and runs by leveraging the graphics acceleration feature of IE 11. Those sites are heavy graphics enabled sites using the WebGL technology. He was trying prove that, we can build really big apps / think clients using HTML/JS combination and render in browser itself.

Google glass with C# By Mike Heydt

What I expected

Since google declared that the same OS can be used in everywhere and any device, I was curious how they provide the API or build the programming model. Each and every device will differ so it may end up like so many if conditions in the code or if we think from the OS side it may need to deploy libraries which may not be used at all in particular device. As most of the sessions are having code demos, I was interested in C# code which can be deployed into the glass.

What I got

First of all, he has a glass and he wear the glass all the time. He showed the physical architecture of the glass such as where is the CPU, battery etc...Then explained the UI design principles. Mainly we need to use cards instead of activities. We can tap and slide using our fingers on the right side of the glass. The major draw back I saw it the inability to debug using simulator. We must need a hardware glass to do test or debug our program. So I decided to get out from the session.

Restful routing in ASP.Net MVC By Khalid Abuhakmeh

What I expected

Again this is a session which I didn't plan to attend. But something which I am interested as there was big fight between me and rest of the team regarding developing an ASP.Net MVC web site in the ReSTful way. That site was supposed to manage our own cloud like server environment which consists of database servers, processing servers, queues etc....All those things can be viewed as resources so I was arguing for ReSTful MVC page urls such as www.site.com/queuetype/2/queue/3 to point a resource and do the contextual operations inside it, instead of operation wise screens such as www.site.com/ListQueues?queuetype=2&queue=3 or www.site.com/AddQueue. It was difficult to make them understand and finally I gave up.

What I got

I came to know about a really nice library named RestfulRouting. Some more pros to provide as proof for my approach towards developing website using the ReST principle if we the requirement is to control resources.

WCF is dead. Long Live WCF! By Michael Montgomery

What I expected

I really got confused about this title. May be he will tell some new ways to leverage WCF features or tell about extensible featuires and all

What I got

He kind of proved that the way we are using WCF for distributed computing / SOA is not the best way. He is against all most all the configurations in WCF. According to him the WCF config values should be determined by the program not by the person who deploys the app. Really speaking last week we were struck with production issues which were caused by wrong values given by the deployment teams. We suggested to use server with minimum 32GB and they installed in a 6GB server and started complaining about the application. Ideally if there is 6GB of RAM in the server the application should have worked at all. Similarly we used to receive so much issues because the deployment teams will change even the protocol of WCF binding. Simply from netNamedPipe to NetTcpBinding without any consultation and when it fails the complaint will be filed.

This gap can be eliminated if the application (WCF layer) can adjust itself with the system. But it really needs homework in the area of load testing and leverage the WCF extensible features. He even showed how the pseudo code for such a WCF communication app can be built.

Knockout.js (Anti)Patterns By Tim Plourde

What I expected

More details about internal working of Knockout.JS and the anti patterns

What I got

Great tips how to avoid common problems in Knockout.JS. As its very easy people tend to develop very fast but soon it will result in performance and maintainability issues. He even have a nice site where he explain everything. I was really impressed the way he presents. He just goes to his site and explains from there. He also explained about knockout linting where we can easily analyze our code for what went wrong.

Overall it was a good experience. Variety of food items for the buffet.

Tuesday, June 24, 2014

Philly.net - Code Camp 2014 - Day 1

I was really excited to attend the Philly.Net code camp 2014 event as this is my first developer community event after I reached America that too with the reimbursement from my company. My expectations were huge as there are many MVPs taking sessions and can mingle with more intelligent and smart programmers. As of my analysis, ideally if somebody is smart, they eventually end up in United States provided they don't have his old parents who don't want to go US. Another interesting factor is the organizers will distribute more goodies / gifts to the attendees as they are taking registration fees :-)

The biggest difference from the events I had attended India and this code camp is the number of sessions and its schedule. In India the events I had attended conduct only one session at a time because audience and speakers are comparatively low in number. Regardless of the interest in the session, we had to sit until the next session starts. But here in Philly.net code camp there are around 72 sessions to be conducted in 2 days and there are 8 stages which means 8 sessions will go in parallel. In one way its good that we don't need to sit in a session which is boring. But in the other hand, if there are 2 or more sessions we want to attend, we can't.

Anyway just noting down my experience in the format of 'what I expected' and 'what I really got'. Selection of session was really tough as there are at least 2 sessions interesting at any time slot.

JavaScript for Devices by Andrew Duthie

What I expected

It will be purely hardware related where he will explain about boards such as Raspberry Pi / Arduino and show demo using the board. The javascript execution environment needs to be installed into the board where we can execute our javascript code. The javascript to hardware binding would be done using Assembly or C language and those details may also in discussion.

What I got

As per the short description in the schedule, he started with a presentation which tells what is micro controller and what is Espruino board and compared it with other board Tessel. These are the boards which are supporting the javascript out of the box. After 4-5 slides he started demo. Normally I have seen people showing demo about hardware in simulator as it is difficult to show the device to the entire audience. But for the demo he just used a camera which is on the table where he is playing with the device. As its connected to USB port, he was able to project it. Simple solution. Everyone can understand what the board is and how it work.

The board is connected to his laptop via COM3 and he used a program called Web IDE to communicate to the device. The Web IDE supports interactive mode as well as program mode. In program mode we write the program in the Web IDE and just push to the board and it start execution.

The board contains many LEDs, I/O pins which can be programmed using javascript. He also demonstrated how to read temperature using sensor connected to the board, started fan, LED matrix board controlling etc...

It was really nice, I got more than I expected. But only thing worrying me is the price $99 of the Espruino board. 

Refactoring to a S.O.L.I.D foundation by Stephen Bohlen

What I expected?

Ideally I planned to attend another session named "Using Azure to analyze Yammer data". But unfortunately that session got cancelled. So thought of attending this all time favorite SOLID session. I had attended couple of SOLID sessions earlier and myself took SOLID sessions to the developers. Whenever I took sessions the audience had complained about one thing. SOLID is good in theory and easy to talk but difficult to follow especially when we are working in delivery oriented service companies. So thought of getting some practical tips from this session which I can pass to my fellow developers

What I got

The session went well. He started with the 'swiss army knife' image to describe Single responsibility principle and reached to Dependency inversion very quickly. He started with an console app which is printing report and modified the same example to show all the principles throughout the session. I thought 'oh this is yet another session about SOLID". Then he started giving some practical tips. Peter Parker principle, Boys scott principle etc...Finally an advice of "If you have a huge legacy code base, refactor only the areas which are changing / going to change frequently". Why to spend time and money by refactoring the areas which are not going to change at all?

Another interesting information I got is about the .net exception class NotImplementedException. As per him this exception is added into framework to make sure all the auto generated code segments are getting compiled. For example we can use the IDE to implement the interface methods, if this exception is not there, the generated code will not compile. But as per the design of automatic code generation, the auto generated code should not create compilation errors hence they created this exception in framework. But in production code this NotImplementedException should not be present.

Practical machine learning - Recommender engine & anomaly detection by Seth Juarez

What I expected

To be frank I have not paid much attention towards Mathematics in college as I was thinking, that is not required for a computer science student. I concentrated in improving my logical skills and problem solving skills and up to an extent I succeeded in it. There was nobody to show me the practical uses of Maths in programming. If there was one, I should have given more attention towards it. 

I realized the problem when I was asked to draw a spiral 3D image in WPF as part of project requirement. From that time, I started paying attention towards maths. The same problem hit me when I started studying data analysis. It requires a huge amount of statistical knowledge along with other areas of Mathematics. So I was expecting a session where I can learn data analysis techniques very quickly.Kind of hacks. Also he might explain how the analysis can be applied in real life applications.

What I got

He started explaining what is the difference between science and engineering and why data analysis is called data science. As we all know in science, we cannot guarantee the success. We may get a solution or we may not. Its all research. I was happy as it enforced my view about data science.

Then he explained about different types of machine learning algorithms such as supervised and unsupervised . Then K-Means algorithm. I was trying hard to learn that for some long time. But after he demonstrated that algorithm using his own sample application, I was able to catch it up very quickly. He nicely explained how the distance calculation is used in these algorithms. Then session moved to recommender engine and finally to anomaly detection.

Debugging production web applications on IIS by Ed Ferron

What I expected

I have taken 'Debugging production apps' session in my company. So I was eager to get more practical oriented tips and tricks instead of how to create memory dump using DebugDiag and analyzing it using WinDbg or Visual Studio itself. I was also interested in tools which can make the debugger's life easier.

What I got

He explained pretty much same things like how to get memory dump and analyze it using WinDbg. I don't think he touched even the PerfView or how to debug the app using ETW logs. The interesting information I got is about intelliTrace and its collector which is the 'rich developer's tool'. When I was working in India VS Ultimate was our ultimate dream, which company never provided. But here in same company's US office, same project everybody has VS Ultimate. So now I can start thinking about intelliTrace.

Create an RDBMS-free app by David Hoerster

What I expected

I was expecting a guy who believes only in open source and he will explain details about how an application can be built without SQL Server or Oracle RDBMS. Also I can learn how transactions can be managed using NoSQL databases such as MongoDB.

What I got

I got an idea how we can introduce non RDBMS into applications which is running RDBMS. It will end up as a system where there will be RDBMS as well as non relational databases. His suggestions was to use non RDBMS for searching and storing logs. Interesting thing was he never mentioned the word NoSQL in any of his slides or sentences even though he talk about NoSQL systems. According to him the logging and search index updation doesn't need any transaction so its good place for non relational databases.

This was the one only session I have seen one person falling with his chair. I think he was sleeping.

Improving your application architecture by Ravi Okade

What I expected

So much expectations such as how to architect systems, how to select programming languages, how to scale etc...

What I got

He started with very basics such as what is data structure and what is algorithms. Explained about the sorting techniques. With each and every sorting technique, he was telling that its already taken care by .Net framework functions. Then he told about how to select serialization method for our applications. Interesting thing I got from this session is, the names of serialization protocols such as Apache Thrift, Microsoft Avro etc...He showed some comparison screens for different serialization techniques. 

The time was already running late and didn't find it much interesting. It sometime felt like he is reading the slides. There was no code too. So thought of searching for his slide sometime later.

Day 1 Overall 

  • 8 sessions are running in parallel so difficult to attend all the session which are interesting to me
  • The stages don't have good separation. So most of the time we can hear 2 speakers. Else the seat should be just opposite to the speaker in the front row.
  • Most of the sessions used less slides and more code. Really oriented towards programmer community.
  • No video recording was happening. If they record the videos, it would be really helpful to view the missed sessions.

Monday, June 16, 2014

You need to install the latest Silverlight Developer runtime before creating a Silverlight project

After a long gap, I installed Silverlight in my development machine to look into a performance issue in an internal company tool. As per the policy the "internal projects don't have the luxury of testers" so the actual testing happens on production hence so many issues especially performance. Its a Silverlight 5 project and I installed the Silverlight 5 tools from the Microsoft site. When I tried to open the solution the first error I got was given below.

You need to install the latest Silverlight Developer run-time before creating a Silverlight project
Download runtime at <url>

I thought, the Silverlight tools version I installed may be 32 bit version where its expecting 64 bit version. So downloaded the version which is mentioned in the error dialog. But when I tried to install it, the next message came.

Newer version of Silverlight is already installed

Interesting. Now no other way remove all the items from control panel by searching the word Silverlight and install only Silverlight 5. This I had did so many times when in active development of Silverlight applications. But this time that too didn't help. So decided to google.

The solutions people provided in internet are different. Some says we need to follow the link provided in the visual studio error message some posted a link from where we should download the run time, another one suggest to install Visual Studio 2010 Service Pack 1 to get Silverlight 5 working.

Installing VS 2010 SP1 takes more time, that is one of the reason why I didn't install it. As there are no other option I had to install VS 2010 SP1 and it started working!!!

These are the occasions, we think about the error messages we coded which is absolutely useless for the users. Thanks Microsoft...

Monday, June 9, 2014

We can't eat all the .Net exceptions using try catch block especially ThreadAbortException

Background

It is generally not recommended in .Net to control the application flow by throwing and catching exception. But in some cases people does it, to safely do the thing. In one of the WCF component in my project there is one scenario where the application flow is controlled via exception. The main intention was to keep the exception inside the thread itself and return a wrapper which says there was exception or not. Below is the stripped down code just for understanding.

internal class LongRunningProcessCaller
{
    private delegate ResultWrapper InvokeAsync(bool parameter);
    public void Invoke()
    {
        InvokeAsync invoker = new InvokeAsync(CallInvokerThreadHandler);
        invoker.BeginInvoke(truenew AsyncCallback(InvokeAsyncCompleted), null);
    }
    private ResultWrapper CallInvokerThreadHandler(bool test)
    {
        try
        {
            LongRunningMethodWhichMayThrowThreadAbortException();
            return new ResultWrapper();
        }
        catch (Exception ex)//All the exceptions should be caught and pass via Error property
        {
            return new ResultWrapper() { Error = ex };
        }
    }
    private void InvokeAsyncCompleted(IAsyncResult result)
    {
        InvokeAsync asyncDelegate = (result as AsyncResult).AsyncDelegate as InvokeAsync;
        //This method will hang, if there is any exception in CallInvokerThreadHandler
        ResultWrapper invokerResult = asyncDelegate.EndInvoke(result);
        if (invokerResult.Error == null)
        {
            Console.WriteLine("Errored");
        }
        else
        {
            Console.WriteLine("Worked");
        }
    }
    private void LongRunningMethodWhichMayThrowThreadAbortException()
    {
        System.Threading.Thread.CurrentThread.Abort();
    }
}
class ResultWrapper
{
    public Exception Error { setget; }
}

The problem

It went good for some time in production and slowly we started getting inconsistent issues from production. As it is inconsistent, we were not able to reproduce in dev machines and fix it. If we look at the code we can understand that inconsistent issue may happen, in case the catch inside CallInvokerThreadHandler() didn't eat and convert the exception properly.

The debug process

Since its using async delegate invocation mechanism we started thinking about exception behavior in threads and find nothing much. Then we put instrumentation code in catch block and pushed to environments where this issue is reproducing. This leads to investigation of ThreadAbortException which we were not expecting in normal course.

Further google about how to handle ThreadAbortException in IIS hosting environment, gives information only regarding the ASP.Net web sites related to Respose.Redirect. Some sites suggests to join the threads.
One says to resolve this exception, we can just increase maxConnections in web.config.

The Root cause

But our problem is different we have WCF service which calls another WCF service in different thread. The different thread is needed because the second WCF call is time consuming say 2-3 hours. Since the new thread is long running, there are chances for that to be aborted due to various reasons. Our aim should be to handle the failures properly. But what was the problem in the code listed above as it seems to be doing the purpose?

The root cause is, The ThreadAbortException  cannot be eaten by the catch block and we were relying on exception eating behavior.

So if the ThreadAbortException occurs the wrapping of the error result for returning to the completed handler will not work. The runtime will re throw the exception at the end of the catch which will make the EndInvoke in InvokeAsyncCompleted() to wait infinitely.

So rewrote the code as follows by avoiding the async completed handler.

internal class LongRunningProcessCaller
{
    private delegate ResultWrapper InvokeAsync(bool parameter);
    public void Invoke()
    {
        InvokeAsync invoker = new InvokeAsync(CallInvokerThreadHandler);
        invoker.BeginInvoke(truenullnull);
    }
    private ResultWrapper CallInvokerThreadHandler(bool test)
    {
        try
        {
            LongRunningMethodWhichMayThrowThreadAbortException();
            Console.WriteLine("Worked");
        }
        //All the exceptions should be processed here.
        //This is because the runtime rethrows ThreadAbortException from catch automatically.
        catch (Exception ex)
        {
            Console.WriteLine("Errored");
        }
    }    
    private void LongRunningMethodWhichMayThrowThreadAbortException()
    {
        System.Threading.Thread.CurrentThread.Abort();
    }
}

Happy coding...