Posts

Session and Cache are By Reference

Recently a colleague remarked that if he got a List of some type out of the ASP.NET Cache, and changed an item, the Cache item would also change. That is correct. Session (InProc) , Cache and Application all return "live" references. A good writeup on this can be found by friend and fellow MVP Rick Strahl here: http://www.west-wind.com/Weblog/posts/1214.aspx If you do not want this behavior, you need to either delete the Session / Cache / Application object and replace it with what you want later, or store a clone by duplicating the object, doing your work on the original that you got out of Cache, then replacing the existing cached item with your clone that was not changed. for example: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace CachebyRef { public class Person { public String FirstName { get; set; } public String LastName { get; set; } } p...

When Job Growth Is Not Job Growth

The Department of Labor just reported that in February, employment fell by fewer-than-expected 36,000 jobs with the unemployment rate steady at 9.7%. While we may hear the Obama Administration or Harry Reid trying to spin this as some sort of economic victory for their stimulus or otherwise trying to put the best face on the economy, this is in reality not very good news. Let us remember that job growth needs to be around 125,000 jobs gained per month just to keep up with US population growth. To make up the roughly 10 million jobs it would take to get us to an employment situation about where we were near the peak of the economy, we'd have to see job growth of 350,000 per month for four years straight. Such a scenario seems unlikely while we live under the umbrella of the Obama-Pelosi-Reid cartel. The Obama Administration has quintupled, in just one year, the deficits that took its predecessor Bush eight years to create. Looking at the current stagnation in employment, in large pa...

String.Empty vs “” vs String. IsNullOrEmpty

I was reading up on this recently and a couple of interesting points came to light: myString = “” creates a new instance of type String. myString = String.Empty does not. The key item is doing comparisons. Here’s some sample test code: class Program { static void Main(string[] args) { String myString = ""; long a, b, c, d, e, f; Console.WriteLine("Method 1..."); a = DateTime.Now.Ticks; for (int index = 0; index { bool isEmpty = myString == ""; } b = DateTime.Now.Ticks; Console.WriteLine("Method 2..."); c = DateTime.Now.Ticks; for (int index = 0; index { bool isEmpty = myString.Length == 0; } d = DateTime.Now.Ticks; Console.WriteLine("Method 3..."); e = DateTime.Now.Ticks; for (int index = 0; index { bool isEmpty = String.IsNullOrEmpty(myString); } f = DateTime.Now.Ticks; var Method1 = b - a; var Method2 = d - c; var Method3 = f - e; Console.WriteLine("Method 1: bool isEmpty = myString == \...

Crunch Time for Visual Studio 2010

Just a note to beta testers, MVPs and others who are “exercising” Visual Studio 2010 RC: This is the time to get your stuff in to Microsoft Connect (or other appropriate venues) – as quickly as possible . I’ve already submitted several issues (mostly minor ones) and I see that the C# Insiders listserv has been very active with discussions. The sooner you can identify an issue and give the appropriate dev team a heads –up so they can check it out, the better a product we’ll see at RTM release time. Visual Studio 2010 is going to be a really great product - and there is still time for us to help make it even better. Thanks!

SQL Server 2008 64-Bit vs 32-Bit Performance

I’ve got an x64 machine I do most of my “hard core” development work on, that I’m very happy with. I’m running Windows 7 Ultimate x64 and have had few problems. The box only has 4GB RAM, but I almost never hit the ceiling with that, no matter what the heck I do. But recently, we needed to do some work on a database that has some tables with close to 6 million rows, and I needed to build FullText catalogs for some of them. That’s where SQL Server 2008 x64 crapped out . I had memory consumption issues that caused me to have to hold the power button down for 4 seconds just to be able to “get out of Dodge” if you will -- several times too. Mouse didn’t work, machine was unresponsive, etc. – just building a FullText catalog on this big table. Now I don’t care about all the KB’s and suggested “Fixes” and all that. I haven’t got the time to futz with this crap. So I said, OK, let’s get rid of this sucker and see if the x86 version of SQL Server 2008 does better. So I did, and guess what...

ASP.NET MVC – Do I Really Need It?

As a professional software developer, particularly of the Microsoft flavor, you get bombarded with “new stuff”. If you do not instill in yourself a certain discipline, you are sure to be brought down by the sheer complexity of tackling every “new thing” that is sent your way. I say this from personal experience; I do not mean to be negative in any way in saying this. It’s just a fact of life. There are so many “CTPs” and new technologies being thrown at you that it is easy to succumb to “Beta-itis” – the debilitating compulsion to download and play with every new thing, to the point where your productivity as a software developer begins to suffer. It’s even worse if you’re an MVP because when you go to the Summit each year, they throw a whole truckful of even more sexy new “Stuff” at you. Sometimes, its stuff that nobody else has seen before and you had to sign an NDA saying you wouldn’t talk or blog about it. Talk about getting excited! ASP.NET MVC is an example for me. About a ...

SQL Server 2008 Fix: SP1 Install Failure

  For quite a while I could not install SQL Server 2008 SP1, as it reported a failed shared component installation – in this case, Books Online. Problem is I could not find the source MSI to fix it. So here is how I solved the problem:  If any shared components installations result in a failed state, a Registry key is updated. SP1 reads these keys when it starts, and if the value is not “1” (in my case it was “3”) – it will stop. Seems ridiculous to me, but that’s how they do it. And doing a repair may not fix it either – because you may have installed Books Online from an interim standalone MSI installer. if you try to find the original MSI to handle the repair, it might not be the correct one. Edit this key (or the respective key for whatever your fail message says) and ensure that the value is 1: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100\ConfigurationState\Sql_BooksOnline_Redist That took care of that problem! Now I have a different issue, b...

Why the Economic Stimulus Plan Doesn’t Work

When President Obama was elected, the economy was already sick and getting sicker. If nothing was done, his economic team said, the unemployment rate would keep rising, reaching 9 percent in early 2010. But if the nation embarked on a fiscal stimulus of $775 billion, mainly in the form of increased government spending, the unemployment rate was predicted to stay under 8 percent. Obama bought into a classic Keynesian solution – and so did Congress. Congress passed a huge fiscal stimulus that focused almost entirely on government spending. Yet things turned out worse than the White House expected. The unemployment rate is now in the 10 percent range — a full percentage point above what the administration economists said would occur without any stimulus ! So what should they  do now? The administration seems  determined to stay the course, although recently, the president showed interest in “increasing the dosage” – a bad prescription indeed. A better approach might be to r...

Don’t Break the Interface

Recently while contributing to a test suite that covers some 250 C# DAOs (Data Access Objects) I discovered a couple of issues: 1) There was an implementation of “PrimaryKey” which is defined as a nullable long (long? PrimaryKey) that returned a 0 (zero) if the nullable type had no value. Uh-Oh! 2) There was more than one implementation, e.g., this actually appeared in more than one base class, in different assemblies. Depending on which references you had set, you could get clobbered! Needless to say we’re going to fix that quickly; there are objects that are “older code” that need to be updated to reflect the change. Fortunately our test suite will show immediately which guys need to be updated,underscoring the importance of having robust unit tests. But the real question is, “How did this creep in”? The answer: Most probably, "Stinkin' Thinkin'" by developers. Nullable types are instances of the System.Nullable struct. A nullable type can represent the normal range...

The big Silverlight 4 Question

You get all this honking and hoopla and what not, but nobody seems to think about the big Silverlight 4 Question: Can I install Visual Studio 2010 Beta 2, Silverlight 4 Tools, WCF RIA Services, The November 2009 SIlverlight Toolkit, and Blend 4 Trial on the same machine that I have Visual Studio 2008, Siverlight 3, SIlverlight 3 Toolkit, Blend 3 and so on – and will they co-exist peacefully on the same machine? Answer: Yes! All you may need to do is uninstall your previous RIA Services Preview. Everything else will “just work”. I just did it and tested it all out. Bart Czernicki mentions an issue that you can review here . Disclaimer: No animals were harmed in the creation of the UnBlog post. Your mileage may vary. Oh, and one final note: If you are going to install WCF RIA Services with Visual Studio 2010, you will no longer be able to use RIA services with Visual Studio 2008. They don't install "side -by-side".