Scott Hanselman

Catching RedBits differences in .NET 2.0 and .NET 2.0SP1

October 15, 2007 Comment on this post [6] Posted in ASP.NET | Learning .NET | Microsoft | Programming
Sponsored By

When you install .NET 3.5 on your system, while the .NET CLR is the same and runs the same, there's some additional Properties and Methods that were added to the Base Class Libraries in order to make some 3.5 features like LINQ work as well as fix a few customer issues.

Daniel Moth has a very nice diagram explaining what "RedBits" and "GreenBits" mean.

"When we say red bits, those are Framework bits that exist in RTM today i.e. NetFx v2.0 and NetFx v3.0...When we say green bits, we mean brand new assemblies with brand new types in them. These are simply adding to the .NET Framework (not changing or removing) just like Fx 3.0 was simply adding to v2.0 without changing existing assemblies and without changing the CLR engine."

Krzysztof has a blog post about these new (kinda obscure) APIs and fortunately a nice FxCop Rule you can drop into your C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules folder and you'll get a nice warning if you bump into one of these APIs. To be clear, they are not something you'll bump into in your regular life, but it's possible. Dan Moseley blogged about this from the MSBUILD point of view.

The situation you might get into would be that you'd develop on a Visual Studoi 2008 system with .NET 3.5 and targeted .NE T Framework 2.0 (but you have 2.0 SP1 with these new 2.0 methods), then you deploy to an older system that has only .NET 2.0 RTM (not Service Pack'ed). At this point you might get a MethodMissingException because that older system might not have the new method or property. Of course, you could just install the latest 2.0, but if you don't want to, then don't use the new methods/types/properties. Hence the optional FxCop Rule.

1473897382_374fc28d10_o

Krzysztof send me a text file with the list of new Properties and Methods and I wrote a little program to generate an HTML file that shows the additions (many are new overloads) and links them to MSDN help. I couldn't get to the exact method overloads so do make sure the parameters line up when you're reading the help.

http://www.hanselman.com/blog/content/binary/RedBitsChangesv2.html

NOTE: This is a different list from the original diff I did between 3.5 and 2.0. The original list was the differences between all of 2.0 and 3.5 and this list is JUST the BCL. Just the core.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
October 16, 2007 2:12
Scott, the rule Krzysztof provided will only work with the integrated code analysis feature in Visual Studio and not with the stand-alone version of FxCop. I talk about this in my blog post here and also provide an updated version of the rule that will work in the stand-alone FxCop.
October 16, 2007 14:43
Scott,

which is the code should I add to my app as first instructions (for example in Main method) to check if 2.0SP1 is installed and then alert the user and stop the application? So when I install an 2.0SP1 application on a machine without it, when I start application to test I know that i have to install it! And I hope that ClickOnce will be updated as well...

Thanks in advance,

Marco Parenzan
October 16, 2007 23:23
On this post I explain how to compare .NET 2.x and .NET 3.x bits with NDepend and how to explore the diff with the Code Query Language.

Actually, this works for all .NET assemblies except the .NET framework ones because the analysis code still relies on System.Reflection and System.Reflection cannot analyzes another version of itself. I cheated a bit to write the post by doing 2 analysis on 2 machines with a different version of the .NET framework and then compared them.

Before the end of the year, the analysis code will be refactored and will allow comparing Microsoft assemblies. For this, I'll use the great Mono.Cecil framework.
October 26, 2007 16:47
Please, is there a list of "red bits" in .NET Framework 3.0?

I am compiling the following code in Visual Studio 2008 beta 2 with target framework version set to 3.0
ICollectionView view = CollectionViewSource.GetDefaultView(collection);
view.SortDescriptions.Clear();

I am getting an "unsupported" exception when I run the program with non-sp1 .net 3.0 installed. (once I install and uninstall .NET 3.5, the problem is fixed). I am guessing this is the same problem you have described here, but I can't find a list of changes in .net 3.0 sp1 anywhere
thanks for any ideas


October 30, 2007 13:06
Jaroslav - I'm working on getting these for you.
November 05, 2007 12:38
Thanks a lot, Scott.
To anybody who might see the same behavior I do: Apparently, any view, default or not, for a collection of type Dictionary<a,b>.ValueCollection is not able to do sorting or grouping without SP1 for .NET 3.0. Filtering works fine. This means that the red bits for .NET 3.0 apparently include sorting and grouping support for views of new types of collections.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.