Posts

Shocker! - Do not use Environment.MachineName

I first found this article after I got an issue:  http://blogs.msdn.com/b/brada/archive/2005/08/10/449767.aspx Let me go around to clarifying this further, and how I re-verified this issue http://msdn.microsoft.com/en-us/library/system.environment.machinename.aspx MSDN clarifies that this is NETBIOS name. http://en.wikipedia.org/wiki/NetBIOS Wikipedia clarifies that NETBIOS name has 16 characters, but Microsoft uses only 15 characters for the same. http://msdn.microsoft.com/en-us/library/system.net.dns.gethostname.aspx This is what should be used.

Living with Windows Driver woes

One of my colleagues used to work for MS before and his job was to look at the windows crash logs and determine what went wrong. Most of the time, he used to find out that it was a problem with the processor or the drivers for some hardware components. As anyone who has ever tried to host servers by themselves know, it is critical to keep them updated so that the PC works fine. Especially when developers like us install 2008 R2 on a laptop and sometimes not all the drivers get installed properly. Windows Update does not always show missing or out of date drivers. Do the following which might surprise you: 1) Go to http://www.driverdetective.org/  and install their software. Do not install Norton with it. 2) Scan your laptop/ desktop/ server. 3) In most cases you will find some drivers out of date or not even installed. I saw this with a brand new server from Dell which did not have the chipset drivers installed. Once you find what is out of date or missing, it is easy t...

Using Visual Studio Remote Debugger between servers in different domains

Sometimes, you might want to use the visual studio remote debugger between 2 servers - one in the domain, and the other outside it. Usually, if you try to do this, it will error out saying that the machine outside the domain cannot connect to your machine. Even if you try to put the credentials in the control panel - users area it will still not work. Well, you know that the remote debugger itself has an option for debugging without authentication. What I did not know was that Visual Studio 2010 SP1 can also debug without authentication. Just open the top combo box to see another option, if you select it, it will now let you debug, although note that this is not secure, so use this warily. Remember to first go to the server where you want to debug and open the remote debugger > Tools > Options > No Authentication, and Allow any user to debug. Then select transport as Remote (Native only with no authentication) in VS and the qualifier is the remote server name. The ...

Keeping your original WCF config file and making it run in Azure as a worker role

If you get 405 errors while trying to access the WCF service with GET enabled in the config file, note that you will need to modify the config file behaviors area right next to where you enable httpget to the DNS name of the azure deployment: x.cloudapp.net Otherwise, no matter what you do, you will not be able to get the browser to access the WCF URL. This is when you have HTTP end points for the WCF service with internal endpoint of azure. if  (!InAzureCloud && !InAzureEnvironment) {  return ; } RoleInstanceEndpoint externalEndPoint =  RoleEnvironment .CurrentRoleInstance.InstanceEndpoints[ "EndPoint" ]; Configuration  appConfig =  ConfigurationManager .OpenExeConfiguration( ConfigurationUserLevel .None); ServiceModelSectionGroup serviceModel =  ServiceModelSectionGroup .GetSectionGroup(appConfig); ServicesSection servicesSection = serviceModel.Services;       ...

Handling "System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL" Exception in Compute Emulator with Windows Azure SDK 1.5

The only other post I found online does not properly explain how to fix this issue: http://blogs.msdn.com/b/avkashchauhan/archive/2011/10/03/handling-quot-system-servicemodel-addressalreadyinuseexception-http-could-not-register-url-quot-exception-in-compute-emulator-with-windows-azure-sdk-1-5.aspx Just go to your app.config file, and in the binding tag for all the services, specify: hostNameComparisonMode = " Exact " For custom bindings, this can be specified as shown below: < customBinding >         < binding >           < httpTransport  h ostNameComparisonMode = " Exact "  /> </binding> </customBinding>

Understanding Microsoft Software

Sometimes it is necessary to understand how MS as a company is moving forward to get an idea about the best way to go forward with your code at the high level. I have already explained in another post how MS badly screwed up for a long time, because of their monopoly and they felt that they could reuse everything they had already built in future products. After the iPhone, they probably realized that they would die if they continued to hoist Windows Mobile 6.5 on consumers. Once the iPod touch was released and it was a bug hit, they started a change in the way they developed new products. It started with the Zune, where they built the OS for that mostly from a fresh, clean slate, and that became a success (w.r.t MS products), and they have followed the same principle for Windows Phone 7 as well. Just because there is something like MS Enterprise Library does not mean that we should batter our code with it, or integrate with it, especially now that it is a monster with several hun...

Some .NET Gotchas

1) For.. Each vs For... I have often wondered what is the difference between for..each and for loops in iterating over collections, because I always use the regular for loops. Today, I found out one major difference - if while iterating over the for..each, I add an item to the list being iterated, the for.. each loop will not go over this newly added item. On the other hand, if I use a regular for loop using the length of the collection, and I add an item to the list, it will also get iterated over. 2) Using LINQ and unexpected behavior... For whatever reason, I am observing that if I use LINQ to find an item from a collection, and later I check to see whether the original collection contains this item, then it always returns false. 3) Using Generic Lists I was very surprised to see that, sometimes .Contains() does not work properly, I have to use Exists() and then write a delegate to check for the existence. The same problem manifests when removing an item from the list...