Posts

Showing posts from 2012

Why Azure Worker Role was taking time to process request

This had been a mystery for a month. I used wireshark to trace that the request was reaching azure, but azure was responding only after 2 minutes. I used wireshark filters like the below: tcp.port = XXX Also: (ip.src==X or ip.src == Y) and (ip.dst == X or ip.dst == Y) All that turned out is that the service was receiving the method call 2 minutes after the server got the request from the client. Turned out that the WCF service constructor was doing a 2 minute long activity each time. I just prevented it from doing it everytime, and ensured it is done once when the service starts up, rather than on the constructor of the WCF service. Sometimes the problems are with old legacy code which does bad stuff. Nothing wrong with WCF!

The ridiculous interview experience

I have encountered a few interview questions which I feel strongly enough to talk about.... 1) List all the scenarios where a stack overflow exception can occur . 2) Difference between mutex and lock ? These two questions seemingly different are in the same category - I work on shitty code either I wrote or I inherited from someone else - tell me whether you know about what happens in shitty code. The problem is that if you are a great programmer and you write great code, you may have never have encountered such scenarios before - your knowing or not knowing about this in no way indicates how good you are. I joined the job where they asked the mutex question and rewrote the entire code - their implementation was totally wrong and how they were trying to solve the problem was also totally wrong. Mutex was not the way to go. You are not a less capable resource because your code and design is so good that they did not have the flaws which you needed to know about to succeed in this

Normalization in class libraries

This is a document I wrote a long time ago.. http://sdrv.ms/RVZcrr

StringBuilder explained...

http://stackoverflow.com/questions/3564906/how-the-stringbuilder-class-is-implemented-does-it-internally-create-new-string http://stackoverflow.com/questions/2365272/why-net-string-is-immutable I liked the second link more, because the whys are always very interesting.

Why services like Azure are the future.

I first user Amazon EC2 and then recently I am using Windows Azure hosting my site todayamerican.com on it. At first I used it just to understand why this is so popular and people are moving to the cloud. Many companies may use Amazon EC2 but I see that a lot of IT departments may want to deploy private "clouds" on VM's because of the low running costs. However, services like Windows Azure I feel are more useful because using the cloud as a remote desktop I feel is not really utilizing the full value of it. Even with a web service API, ultimately you still have to deal with installing stuff on these machines and then you realize this is nothing other than your data center sitting somewhere else. The best thing about Windows Azure which any developer or company would like is the fact that applications developed for Azure can be pushed to the cloud without worrying about VMs or servers. And, as an icing on the cake, Windows Server 2012 now allows you to setup an Azure l

Azure projects erroring out after upgrade to october 2012 SDK?

Go to the properties of the azure project you use to publish to azure and in the first tab, click on upgrade to fix the problems. Errors: Unable to import module Diagnostics. No manifest was found schemaVersion invalid

Just because you know the physics does not mean you will be as good as Michael Jordan

I have faced this prejudice almost my entire career. Somehow, for some reason people tend to think that if you know microscopic details about everything you will succeed in the macroscopic world, because you "understand" mode. In reality, what I have seen is that people who know the most minute details usually stand like scared deer looking at the headlights of an approaching car when they see a real world problem. Why is this? I had to spend sometime blogging about this, because this is a widespread problem. The problem is that, when a platform is built, it is good to have some knowledge of it but diving into an unnecessary level of detail can lead you to wrong places because technology changes very fast - what you assumed as truth in v1.0 might be totally wrong as to how they implemented it in v4.0. What you learned in Java cannot be applied as-is to C#, and wherever you read otherwise, the existence of the garbage collector does not mean you can totally forget about

Changing windows folder locations

http://cduu.wordpress.com/2011/04/02/change-appdata-personal-profile-location-in-windows-7/ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ -> to change user profile folder

General thoughts on Software and Life

I was recently told that mentioning that I had solved problems which nobody had solved before in my job is a sign of arrogance. I beg to differ. There is no arrogance here. Difficult problems are solved by hard work and creativity not brute IQ or intelligence alone. You have to be persistent and you have to keep at the problem all the time till a solution is found. You have to volunteer to solve the problem when nobody is willing to entertain it. So, these people who write books like Mark Zuckerberg was an accidental billionaire is just full of it. Nothing could be further from the truth. He did a lot of hard work with determination and focus - he did not get anything free. So, don't think you are arrogant just because you mention the truth in your resume. Another thing... There maybe a senior developer who may not seem like he can be a great manager because of what he is doing right now. This is also totally untrue. You can't judge how good or bad someone will do i

The longer you spend on a complex problem, the better you will get

I was having this debate with some colleagues recently. In the name of agile, we cannot develop something just for a demo, which you will throw away after that, and then develop another part of the work to be done and then expect things to work out. If the problem is complex, the complexity has to be handled with you hands on its horns. The more time you spend on such a problem, the better you will understand it and tackle it. Doing stuff around it, or over it, actually produces a worse result. Because each time you are not considering the full problem, so your solution is flawed to begin with. Considering the entire problem is difficult, but going over it again and again makes it easier to understand and work with it. QA people also get a consistent application to test. Otherwise they may think your first solution handled some test cases and ignore that later - without knowing solution 2 is totally different than 1, and everything needs to be tested again. It is not true tha

The project is dependent on the following assembly: Microsoft.WindowsAzure.StorageClient.dll. This assembly is not in the package.

I got this weird error today while deploying to Windows Azure. First I installed the latest SDK updates and when that did not fix the issue, I removed the reference to this dll from the web project because it was referencing another dll which was referencing this dll. Not sure why this warning happened. Because I did not have multiple versions of this dll in my system as well. http://social.msdn.microsoft.com/Forums/en/MediaServices/thread/03a7f909-9edf-447a-af04-f73edcdc3113

How to code backwards compatibility into projects

It is simple - you cannot change what has already been shipped. You will always want to do major changes or refactor code especially if you came to the project new. It can be daunting to move forward when you have to consider backwards compatibility. The solution is to keep the old interfaces and entities in place. Create new interfaces and new entities and then use these interfaces and entities. And write code to route calls from the older interfaces to the new interfaces and translate the state from older entities to the new entities.

This is what works...

I have often heard the argument that static methods in C# are thread safe because their parameters are instance values. Or something to that effect. I never really accepted this nonsense but I heard it too many times and started to believe it. Today, I saw something which has fully shown me that this is not true. When multiple threads can enter a method, the safest way and the least complex way to prevent concurrency is to let it be an instance method and let different instances of the object run on different threads. Many guys may say otherwise. But I just saw a case where it clearly is not thread safe and I need to lock stuff to protect it. What is the point of writing static methods and putting lock statements all over the code? - Better for it to be instance methods and do away with this contention to begin with. The best multi-threaded code is code where you split the work and share no resources, so stuff can actually run in parallel and do not have to deal with conten

And C# stopped working...

I had a problem in the production environment of a major customer recently. Windows 2008 R2 without SP1 and some updates, and C# stopped working. Basically, when I used AddRange() to transfer values from one collection to the other, the value did not go across. Note - the value did not go across. The source and target collection had one item in it, but in the source, there was a value, in the target it was NULL or BLANK. I verified that the source collection had a value which was not null and not blank and not whitespace - many people verified over and over again that this was so. This was logged to the file, both using my regular logging and also with a string builder. Many people verified, and reviewed that indeed, the C# executable was failing to copy over a value which it was saying is not null, blank or whitespace to another collection. We rebooted the server, installed .NET Framework updates - but every time this code would behave exactly the same way. Finally to fix

Show boot screen in Windows 8

Had a problem where screen was blank on my PC. I wanted to install another OS. This is an issue because Windows 8 boots so fast, it does not show the boot options. I switched on and off several times... did not work. Then, I removed the power plug and put it in again. Now, when the machine started up, it did show the boot option. I did not have to install another OS, then it started working fine. Weird issue. Update : Turns out that is not what fixes the problem. Basically no matter what you do, it won't show the boot screen. Until you put a bootable disk for another OS into the CD tray. Then looks like Windows 8 shows the boot screen because it thinks you want to install something else. Nice workaround!

Are two SQL Server Connection Strings equal?

using  System.Data.SqlClient; public   static   bool  AreEqual( string  connectionString1,  string  connectionString2)         {              SqlConnectionStringBuilder  connection1 =  new   SqlConnectionStringBuilder (connectionString1);              SqlConnectionStringBuilder  connection2 =  new   SqlConnectionStringBuilder (connectionString2);              if  ((connection1.InitialCatalog.ToLower() == connection2.InitialCatalog.ToLower() ||                  connection1.AttachDBFilename.ToLower() == connection2.AttachDBFilename.ToLower()) &&                 connection1.DataSource.ToLower() == connection2.DataSource.ToLower())             {                  return   true ;             }              else             {                  return   false ;             }         }

Why tracking table in MS sync framework is not fully correct.

We cannot use another table as a stand-in to track changes in a base table. This is because if we update the tracking table tomorrow, that increments the timestamps. In reality, if we are tracking changes to a table, that table itself should have the timestamp column, so that, sync works properly, and does not do more than what it is supposed to do.

Why a developer has to worry about windows updates...

Sometimes the unknown errors thrown by the operating system or plain wrong error messages are corrected and show the actual underlying error with the latest windows updates. Happened too many times with me for it to be a coincidence.

How to increase dpi settings on a server which does not have a video card to support Aero

http://social.microsoft.com/Forums/en/whatforum/thread/282a63c2-bd57-4639-811b-c03c6b82b49b Use the above article and the registry setting mentioned there, increase the text size to use a higher % than 100, then logout. When you log back in via remote desktop from a machine which has an aero enabled graphics card, it will make the text much clearer. Update: You have to set windows to use full blown aero mode with settings for best display rather than best performance. Otherwise, this will not work properly. [HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM] "Composition"=dword:00000001 "CompositionPolicy"=dword:00000000 "ColorizationOpaqueBlend"=dword:00000000 "EnableAeroPeek"=dword:00000001 "AlwaysHibernateThumbnails"=dword:00000000 "UseDpiScaling"=dword:00000000 So I can read register table to get the setting is set or not private bool IsDpiScaling() {     RegistryKey k= Registry.CurrentUser.OpenSubKey

WCF Call breaking when some of the dlls are obfuscated...

You get an error with the following words in it: "WCF obfuscated dll Error line position Element _BackingField from namespace not expected" A moron once told me that there is no need to put DataContract and DataMember attributes for the entity objects anymore. I did not listen, he went ahead and stopped putting it in. Turns out, if any of the moron's entity classes are modified to add more fields later, the WCF call to the server which takes the entity breaks with this weird error. Looks like the obfuscator handles classes with these attributes while it creates problems when the class does not have the attribute. This is why whenever we ran code with obfuscation it failed, while the code without obfuscation from the exact same source code works fine. REF:  http://stackoverflow.com/questions/5921635/is-datacontract-attributes-required-for-wcf

Minor updates incoming

Other than the major performance improvements to the site, you will notice that since yesterday night, the RSS feed will return results for the current day only. So, it should not be old stale news which turns you off.

Creating classes within classes

I know that the MS rules say this is not a good idea. However, I disagree, for example if a method takes a parameter which is an object, and this is not for an API., it is ok to create a class within a class when this class is meant to be used to pass stuff to this particular class only. Better than putting it out in the open namespace, when it is tightly bound to this class only. Sometimes, this is useful for an Enum also. Because then you can have enums with the same name, but within different classes. This often happens when writing code.

Evolution of a programmer

Programmers can be categorized into the below: 1. Those who have no idea about what they are doing. 2. Those who just manage to do the job. 3. Those who can do the job if you tell them how exactly to do something. 4. Those who write code for years and learn by experience doing things differently each time. 5. Those who write code for years and gain experience but always do stuff the same way. 6. Those who have a degree in CS but who have little hands on coding experience. 7. Those who have a degree in CS who can get around decently. 8. Those who have a degree in CS and can talk very well, but do little in the real world. During interviews, choosing a candidate can be a big problem because sometimes we select the guy who can talk really well, but who cannot do any practical work on a day to day basis. The guys who can code really well, may not do well in the interview at all. Sometimes the candidate with the worst feel in the interview, might be the exact fit for the job. T

My Preamble

I am not interested in a job, where you want to hire the most intelligent person you can find, then expect this person to work like a robot exactly like the manager wants him to.  I don’t care about positions myself but because everyone else does , I am only interested if the role is that of a senior manager, chief software architect, etc. I am not a robot, and never will be.  I will never work in North Korea, Saudi Arabia or any environment where these regimes are recreated. Consulting companies are the scum of the earth. Hence, I will never work for a consulting company, period. I will not keep quiet if someone accuses me of something I had no control over. I am not interested in a job, where the previous person left because it was a pressure cooker environment.  I am not interested in a job where the manager could never work with anyone they have hired before, so they are looking for a new person.  I am not interested in a job, where the person who I will report to is not t

Most ugly thing ever invented?

Unity Framework, shortly followed by Sync Framework. If you use either, then you have low self esteem, and try to boost it, by using something someone else has built. 99% of the people who use these should not be working in software development, because they don't have aptitude for software engineering. Try something else like cooking, or hiking, etc. Just because someone else wrote it does not mean, you can shut your eyes and pretend it will solve all the problems. Microsoft please stop creating these ugly, massive frameworks full of defects, with bombastic names which ignorant people use everywhere in their code, making it a nightmare to maintain or to reuse. Calling a simple thing a complicated name, does not make it great. If you do release stuff like this, put the source code in the open so someone can fix this mess, because you don't support it anymore. I can see now how Steve Jobs saw the ugliness in Windows.

Interesting fact about the LINQ to SQL Designer

If you never want to go and set the columns of a table to “Never” update check, then just add a timestamp column to the table, and it will do this for you. Pretty cool!

Optimizing searches through lists

I just finished completing a significantly complex piece of work, and thought I would pen a few words on how I improved the performance of this code. This will help me remember how I did this as well as help the novice programmer: This is how my initial code looked like: for (int i = 0; i < small_list .Count; i++) {       item = small_list [i];       result = (from p in big_list where p.ToLower().StartsWith(item.ToLower()) && String.Compare(p, item, true) != 0 select p).ToList(); } If the size of the small list is “S” and the size of the big list is “B”, every time the code will go through “B” items to get the result. I optimized this code so that I use a dictionary to lookup the results of the search as shown below:         for (int i = 0; i < small_list.Count; i++)         {                 item = small_list[i];                 if (lookup.ContainsKey(item))                 {                     result = lookup[item];                 }             } The dictiona

Miscellaneous Ideas!

How to start a Task in C# which takes parameters: Task .Factory.StartNew(() => Method(arg1, arg2, ...)); How to handle ambiguity in code: You may have a situation where you need to add a parameter to a method in the code which is called from 1000 places. And you do it, and you look at a calling method and realize that you have no idea about what value to pass for the new parameter. What you do in this case, is to add the new parameter as a parameter to the calling method as well. Keep on adding the parameter in the caller method until you reach a point where it makes sense to provide a value, or the user is entering the value. You will always reach a point where you will be able to provide a proper value, as long as what you are doing made sense to begin with. How to handle a crying toddler who does not want to you to brush his teeth: Give him your toothbrush and let him brush your teeth while you brush his. He will be having fun while you get the work done!

How to manually update the BIOS on an HP a1600n desktop with A8M2N-LA motherboard

After wrestling with this over 3 days, I found out a way to update the BIOS on this machine and thought I would post it online. Many people are having difficulty applying the HP update from the HP site especially on Vista and Windows 7. Without this update, the processor does not support virtualization. 1. Download processmon from the windows site after searching on Google. 2. While running the BIOS update, just before it fails, look into the processmon to see which folder the installer.exe is running from. 3. Copy the contents of the temp folder to the desktop before closing the failed BIOS update message. 4. Open the desktop folder and set the winflash.exe properties to vista compatibility and run as administrator. 5. Run winflash.exe, select the 507.rom file from the file menu 6. Select update all in the left side options. 7. Say update on the toolbar. 8. When the modal dialog opens up, select update. 9. Let it update, and it will automatically restart windows 10. When it

Defensive Programming Techniques for any language

Never put code in else. What goes within else can change if someone changes conditions tomorrow. Always check exact a.k.a else if (condition) explicitly. Never assume something of the underlying framework. If the object supports a close + dispose, calling close() maybe a good idea, there was a case where the framework would not actually call close when dispose was called. So this is a good idea. Don't assume that books provide the best practices for anything. Try it out and find the best practices yourself. Your life can be a hell of NULL condition checks when you define properties of lists or complex objects. Maybe the best idea is to instantiate these properties in the constructor so they will never be NULL to begin with? Try not to put any kind of conditions within conditions which make it difficult to read the code, set the IF condition in such a way if possible that you don't even process further if it is false, then the next line of code will be at the same level

How to crop an image in c#

This works: using  ( Image  FullsizeImage =  Image .FromFile(sourceFilePath))         {              using  ( Bitmap  NewImage =  new   Bitmap (FullsizeImage.Width, ThumbHeight))             {                  using  ( Graphics  newgraphics =  Graphics .FromImage(NewImage))                 {                     newgraphics.DrawImage(FullsizeImage, 0, 0,                                            new   Rectangle (0, 0, FullsizeImage.Width, ThumbHeight),                                             GraphicsUnit .Pixel);                     newgraphics.Flush();                 }                 NewImage.Save(outFilePath,  ImageFormat .Png);             }         }

How to enable and generate unit test code coverage metrics in your VS2010 solution

Right click on the solution >> Add file >> Add a test settings file After it is added, VS will open a prompt for the test settings. Go to the Data and Diagnostics section, select code coverage and then click configure (left top in the same section as the checkboxes). Select all projects you want to have code coverage metrics for, other than the unit test project. Close this window, and then click apply. Remember: You can get back to this, by going to the Test menu on the top, "Edit Test Settings" and selecting the new test settings created. Now run all tests in the solution, and after they have completed execution, click on the "Show Code Coverage Results" icon on the extreme right top of the test results pane. You can now expand the heirarchy and see the code coverage results. If you get this error: "Strong name verification failed for the instrumented assembly Please ensure that the right key file for re-signing after instrumentation i

Intel Graphics Woes?

If your laptop is a dell e6510 or has a sandybridge processor with intel graphics, you need this driver: http://downloadcenter.intel.com/confirm.aspx?httpDown=http://downloadmirror.intel.com/20392/a08/Win7Vista_64_152250.zip&lang=eng&Dwnldid=20392&DownloadType=Drivers&OSFullname=Windows+7+(64-bit)*&ProductID=3231 Without it, graphics performance will suffer and your laptop cannot detect external monitors or projectors.

Windbg for IIS

This article is great: http://blog.whitesites.com/Debugging-Faulting-Application-w3wp-exe-Crashes__634424707278896484_blog.htm Just use the below commands instead for .NET 4.0: .loadby sos clr !clrstack

Missing Operating System error on HP server after installing video card

This has caused me quite a lot of grief before, even to having to format the server indavertently. Looks like if the server has an NVIDIA motherboard and you plug in a ATI video card then for some weird reason the BIOS setting for RAID gets reset. It tries to boot from the individual hard disk instead of the virtual RAID volume and throws this error. Simply, go back into the BIOS settings and enable RAID again, and it will boot properly. Go figure! Btb this video card is weird. In VGA it gives a resolution of 1280 X 1024, but in DVI mode, only 1024X 768. Could be a monitor limitation too, as I had never before seen this monitor give me this resolution.

C# enum gotcha!

If you define an enum with the Flags attribute, you expect that when you do an "&" operation with an enum value, you will get back the enum value you are "&" with, only if it contains within the value. Wrong! If you have a enum value with its numeric value set to "0", and you do: value & zeroValue == zeroValue You will always get zeroValue back, even if the actual enum value never had the zero value specified!!

Essential settings for working over RDP

http://social.technet.microsoft.com/Forums/eu/winserverTS/thread/460c8059-4be4-4147-b0b2-907d017cd0b4 If like me, you use remote desktop extensively, and have multiple monitors, etc - you need to read this. I RDP from a RDP session, and now the quality of my RDP session is noticeably better than what was previous. Like the monitor is directly connected to the DVI on the remote server. However, if you do crank up the settings, you will need a gigabit switch between the servers you RDP into. I have one between my server, laptop and desktop. Substitute Remote Desktop Services under the Windows Components tab if you are using server 2008 r2 Enjoy!