|| Wednesday, 08 October 2008
IndexOf has overloads that take StringComparison which allows me to specify how the comparison is done: culture (in)sensitive, case (in) sensitive, et cetera. Why is it that Contains doesn't sport such an overload? IndexOf makes a LINQ query look so much more ugly than Contains...
|| Wednesday, 23 July 2008
I have created another (hopefully useful) checkin policy for Team Foundation Server 2008 - one that checks C# and VB.NET project files for COM references. The idea came from a customer, where they require the developers to use "authorized" interop assemblies instead of developers recreating those by simply adding a COM reference to each and every project. And how do you prevent this? By having a TFS checkin policy in place.
A COM reference looks like this in an MSBuild project file:
Instead of searching for the string "<COMReference" I decided to use the MSBuild Engine API in my implementation:
public override PolicyFailure Evaluate()
PendingChange checkedFiles = PendingCheckin.PendingChanges.CheckedPendingChanges;
ArrayList failures = new ArrayList();
foreach (PendingChange change in checkedFiles)
string extension = Path.GetExtension(change.LocalItem);
if ((0 == String.Compare(extension, ".csproj", false)) ||
(0 == String.Compare(extension, ".vbproj", false)))
if (change.ChangeType == ChangeType.Edit || change.ChangeType == ChangeType.Add)
// this is a workaround because project.Load(fileName doesn't work in the same process as VS
FileStream fs = File.OpenRead(change.LocalItem);
Project project = new Project();
project.Load(new StreamReader(fs), ProjectLoadSettings.IgnoreMissingImports);
foreach (BuildItemGroup big in project.ItemGroups)
foreach (BuildItem bi in big)
if (0 == String.Compare(bi.Name, "COMReference", true))
PolicyFailure failure = new PolicyFailure(String.Format(ComReferencePolicyStrings.activateMessage, change.LocalItem), this);
At first, I tried to load directly from the .??proj files, but Visual Studio (after thinking a bit about it it is pretty obvious...) doesn't like someone inside its process play around with the MSBuild engine. That's why I resorted to loading it indirectly.
For installation I have provided checkinpolicy.reg, however, you must adapt the path to the .dll before importing it into the registry.
Windows Registry Editor Version 5.00
Once registered, you can add it to your team projects:
As usual I have included the source code (BSD licensed) in the download:
ChrisOnNet.CheckinPolicies.ComReferencePolicy.zip (35.35 KB)
|| Tuesday, 10 October 2006
Today, I was asked whether there was a "real" difference between debug and release builds of a C# project - other than the PDB files. I didn't know for sure, so I set out on a search for more information, which turned up the blog entry debug vs. release in C#. The interesting part is the first comment by Josh Williams: "...the /debug[+|-] switch controls JIT optimizations <snip />. Disabling JIT optimizations is very useful for debugging purposes but will very much affect the runtime perf of an app as much of the optmization of your code is done by the JIT, not CSC..."
Now that definitely turns shipping a debug build to customers into a non-starter.
|| Tuesday, 19 September 2006
Beta 1 of SharpDevelop2 2.1 is available for download. While I was putting together the annoucement for v2.1 yesterday, I realized that for a point release, we really managed to put in a lot of new cool features:
A couple of WOW features (for me, at least): Not only can you compile an application for different versions of .NET, you also get version-specific code completion support. Another cool one is that you can host SharpDevelop in your application, providing your application a "macro editor" (on steroids I might add) with full .NET support. And to pick a third, code analysis rounds out our professional offering in addition to code coverage as well as unit testing.
Two features did not make it for the Beta 1 announcement as they don't yet cover all the scenarios we are hoping for: integrated Subversion support (yeah!) and targetting the Compact Framework for Windows CE devices. Those slipped silently into this release.
As you can see, SharpDevelop is ever growing and the developers working on it can be rightly proud of their achievements!
Finally, a kind of "call to action": let us know what you think! Not only in our forums, but also in your blogs, communities, et cetera. We need your feedback regarding feature set, stability, and much more.
|| Wednesday, 04 January 2006
Daniel published the first article in a series about using the SharpDevelop core to build your applications. Those of you tracking the progress of SharpDevelop through the years might be wondering "Aren't there restrictions because SharpDevelop is released under the GPL?" Well, version 1.x is GPL-licensed. But for version 2.0, we changed the license to LGPL. Thus, you can use all of the SharpDevelop2 assemblies in your applications regardless of license.
Aside from the articles, there are videos showing how to write addins for SharpDevelop2. This will get you started with plugging in functionality with SharpDevelop2 via addins (again, your choice of license now!). Be sure to always get the latest bits either via our source control server, or if you prefer from our build server.
Please note that SharpDevelop2 requires .NET Framework 2.0, and, the usual disclaimer, that it is a work in progress. This, however, does not apply to the core - it has been in development for four years+, and as such is very stable and proven. After all, it is the basis for a 300 kLOC C# application!
|| Monday, 05 December 2005
Today, a member of our German .NET community asked if it is possible to programmatically query the Google page rank. He had seen it done in PHP (here on the Google Community site), but didn't have time / PHP skills to translate it. All I found on a rather shallow search was PullRank, which I'd describe as non-fit for server use.
So I decided to set out to convert the PHP sample. Being PHP-challenged myself, I decided to give the PHP to ASP.NET Migration Assistant a shot. Whoha! That converted code is the most convoluted contraption to be called code I have seen - ever. I tried to get it to run, but failed because the conversion left me with some loose ends.
Instead of giving in, I contacted Christian Wenz to lend me a hand because he has some PHP experience. He thankfully hosted an "annotated" version of the PHP script so I could look at the output of various stages to test my solution with known-good values. That was most helpful.
Instead of doing a Web site demo application with everything intertwined, I split up the project into two - GPRDotNet being a DLL assembly project you can reference in any type of .NET application (Windows Forms, Web Forms, you name it), as well as a simple Web frontend to demo the usage: DemoSite.
Querying the page rank is really simple - the following snippet is the code from the "Check PageRank" button event handler:
protected void doCheckPageRank_Click(object sender, EventArgs e)
GooglePageRank pr = new GooglePageRank();
string url = webSiteUrl.Text;
string rank = pr.GetRank(url);
thePageRank.Text = rank;
catch (Exception ex)
// this is rather chatty (telling the end user everything *IS* a bad idea)
thePageRank.Text = "Requesting the page rank failed. Reason: " + ex.ToString();
I want to emphasize that the code for the GooglePageRank class is a rather quick & dirty port of the PHP code and that it does not contain the necessary error handling you would expect for a server-side library. After all, it is just a proof of concept for our community.
Finally, here is the source code: PageRank.zip (26.89 KB)
If you find errors, please leave a blog comment so others know about improvements. Thanks!
|| Wednesday, 16 November 2005
Lunch breaks always tend to end up being cut short by stupid ideas, today by my insistence to use My (from Visual Basic) in C#. To get up to speed on My, I suggest looking at Development with My in the MSDN library. The class diagram graphic will come in handy later on.
Step 1 is to reference the Microsoft.VisualBasic.dll assembly:
Next, we need a couple of includes:
Why those and not Microsoft.VisualBasic.MyServices? Well, My is just an amalgamation of various classes that live in those namespaces: Computer, Audio, ... All the stuff you saw in the class diagram in the article Development with My.
Basically, you now have the functionality provided by My, but not as nicely grouped with a My object as in Visual Basic. To achieve this, have a look at the article C# My Services by Gildeoni Santos, it sports a download for wrapping My. As the code (at the time of this writing) is based on Beta 1 bits, you will have to put in the correct namespace references and pull the My prefix on all class names.
|| Thursday, 10 November 2005
I just finished a Web-based C# to VB.NET converter for .NET 2.0. It took me about half an hour and 20 lines of code. How come? Well, Daniel (#develop 2.0 PM) did a video on NRefactory, which is at the heart of #develop's parsing infrastructure. I took some of his demo code plus some of #develop's internal code converter, and put it into a ASP.NET 2.0 page. Presto, that easy if you can stand on the shoulders of giants.
Oh, and I actually put it online, here is the link: C# to VB.NET converter (you can find the source code for a simpler VB.NET implementation of the converter here).
|| Sunday, 25 September 2005
I already have one box (the Shuttle XPC) that is running Windows Server Codename Longhorn Build 5219. Because it wasn't all that much of a hassle when compared to Beta 1 of Windows Vista, I decided to set up Longhorn on my laptop - and try to work with that installation for a week, while I am in Seattle for the MVP & AspInsiders summits. Boy did I end up with an installation marathon...
Lessons learned in this Sunday's "don't try this at home kids" department:
- Don't assume that ATI drivers for your IBM X31 will install on Longhorn. They refuse, making for rather crappy UI performance. By the way, on failing, setup suggests to install a VGA driver first.
- None of the network adapters were found - neither the onboard LAN, nor the onboard WLAN. When you peek into Computer Mangement, it is your guess which of the two "Ethernet Controller" is which.
- Don't only update the driver for one, even if it is the LAN one. Your ISA 2004 client installation will mysteriously fail. After installing drivers for all LAN equipement, it just works.
- Minor annoyance: the OS-provided sound driver produces hisses et al. Not too bad, but annoying if you plan to watch loads of Channel 9 movies. Your guess is correct: the vendor-provided driver refuses to install.
- No standby. That sucks royally.
- You learned about that in my previous post - no .NET 1.1 for you by default.
- Installing VS can be so much fun, especially if MSXML 6.0 refuses to install as part of the default install. Doing it separately works so much better. And the "Locate File" dialog for the VM driver irritated me only for the better part of a minute...
- Before installing the Atlas VSIs, you better start VS at least once. Otherwise the Atlas installation will fail. Only mildly interesting.
- Do I need to mention that Virtual PC networking doesn't work? That one didn't change for the better, which will make me dual boot into XP.
On a different note: default installs of 5219 have a blank password for Administrator. And IIS 7 is installed by default, which really baffled me. I'm so trained to enable features after install that at first I was thinking it was not part of the bits I got...
|| Thursday, 15 September 2005
Today's first keynote speaker was Eric Rudder. He unveiled the Expression Suite, which contains Acrylic, Quartz and Sparkle. For the latter, go to Channel 9 and watch this video. Also, the Windows Workflow Foundation saw the light of day during the keynote, as well as (last but not least) VSTA (Visual Studio Tools for Applications). You can learn more about VSTA in this blog post.
Eric was followed by Steven Sinofsky, who focused on Office 12. He demoed SharePoint, InfoPath, the new Access and more. I have to say again what I said previously - this is the first time I'm interested in an Office beta program. Good news is that all PDC attendees are signed up, steak knives being strictly optional <g /> (and even more limited than that phone fiasco from day one, 'nough said).
Now, without further ado(.net), the sessions I attended today:
- Windows Vista: User Account Protection—Securing Your Application with Least Privilege Administration
- The .NET Language Integrated Query Framework: An Overview
- C#: Future Directions in Language Innovation
- ASP.NET: Future Directions for Developing Rich Web Applications with Atlas (Part 1)
Anders Hejlsberg did the LINQ (Language Integrated Query Framework) and C# 3.0 sessions. Highly impressive stuff, and I am looking forward to the DLinq session to learn more about the relational access model. I do like to know what is going on behind the scenes, various OR mappers made me wary. In closing: at least now I know why ObjectSpaces made a rapid disappearance...
|| Tuesday, 13 September 2005
The PDC today officially kicked off with a keynote by Bill Gates. To me, the more interesting parts came later in Jim Allchins keynote: Atlas, Windows Communication Foundation, Windows Presentation Foundation as well as C# 3.0 & LINQ. However, Office 12 does look very promising too. Can't wait to get my hands on that beta (never expected to say that about Office, ever).
In the afternoon, I attended the following breakouts:
- Behind the Scenes of Visual Studio 2005 Team Foundation Server
- Windows Server “Longhorn”: What's New for Developers
- Windows Presentation Foundation ("Avalon"): A Lap around the Windows Presentation Foundation
Looking forward to tomorrow, because Windows Workflow Foundation will be revealed at the keynote (aka general session).
|| Wednesday, 09 March 2005
A new Channel 9 wiki has popped up - about performance tips for managed code and related CLR "stuff". A really usefull collection of articles, videos et al - check it out
|| Tuesday, 08 March 2005
Another AppDev training CD has hit the download center: this time, it is the ISO image of the Developing Applications in Visual C# .NET (CD1) training course. Note that in contrast to Exploring ASP.NET 2.0 Using Visual C# 2005, this courseware is for Visual Studio .NET 2003. Download
|| Monday, 27 December 2004
This can be pretty useful to get an idea which open source projects are available, and today I did it (again) for C#. Of course you will see the usual suspects (NUnit, NAnt, RSS Bandit, NHibernate and a lot of others), as well as ones you haven't yet heard of, such as dotLucene (I knew of the Java one) or Report.NET. And on occasion you stumble upon something really wacky, such as Pr0nspider, which is a multithreaded sample for the WebSpider library... this sample definitely drives home the concept!
|| Tuesday, 14 December 2004
Finally found some time to add a few missing things to the registry editor: most importantly editors for string (REG_MULTI_SZ) and byte (REG_BINARY), as well as some other improvements (mostly behind the scenes).
Like last time: please read doc\Program Notes (4 Dev and User).pdf before installing!
Details from ChangeLog.txt:
- Byte editor added (needs to be improved user-input-wise)
- String editor added
- Editors are now loaded via Hashtable and Reflection (easier to maintain)
- Menu restructuring (New Value submenu)
- KeyPress event for DWORD editor modified to only allow numbers to be entered
- New project directory structure
|| Friday, 10 December 2004
I’m one of those next-cool-thing addicts that can’t resist to play with the latest most unstable Whidbey CTP coming out of Redmond. One of the red-hot things is generics that will be included with C#^H^H the CLR v2.0. This intentional blunder is the central point of this editorial - clearing up misconceptions about generics.
When reading postings or talking to fellow early .NET 2.0 adopters you come to categorize those into the following distinct groups:
- The C++ developers
- The Non-C#, Non-VB.NET, Non-Managed C++ developer
- The Java developer (yes, I know…)
- Generics, huh?
Let’s start out with the die-hard C++ programmer, a guy who really is in love with the templating system in C++ (when referring to C++ I really mean the unmanaged C++ world). This is the most vocal among the four groups, and they’ll be very forthcoming in telling you how much better C++ templates are than generics in C#. I hate to break the news to them, but generics are intentionally different: firstly, and most importantly, C++ templates are compile time only, whereas generics are compile as well as runtime. Anders Hejlsberg did a great job of explaining that in , and the C# team has a FAQ online on this topic too .
Secondly, the being different goal also extends to simplicity of use. Do you remember yourself screaming bloody murder when C# came along with single inheritance? Right. How many people did and do care in real life? See. Same here in generics-land: certain power has been stripped from you because it would tip the balance from easy to use to intimidating and overly complicated. That’s why constraints don’t cover the whole complexity spectrum and don’t allow operator constraining and the like, such as non-default constructor constraints. Oh, you can fake operator constraints if you really, really care with the approach detailed in  and , but admittedly this won’t solve the problems for intrinsic types.
Speaking of operator constraints constraints (couldn’t resist), a general misconception in the C++ camp is that everything they are used to should be just as dangerous – pardon me, powerful – in other implementations. C++ templates allow you to do what you damn well please, but generics don’t – that very type checking is the one thing to single out that rid us of AVs, remember?
The Non-C#, Non-VB.NET, Non-Managed C++ developer. So who are they? Try one of 30+ (don’t quote me on the actual figure) other programming languages that follow the CLS (Common Language Specification) and produce code that can run on the CLR. It is rather similar if not exactly the same as with Edit and Continue support – “me too!” is heard all around the globe. So, do they get generics? Depends. Because of the many programming languages that exist for .NET, Microsoft decided to not put generics in the CLS. So it is entirely up to the language vendor in 2.0 to support generics or not.
Has the C#/VB.NET developer any beef with that? You bet. If you write a framework that has to be used in other programming languages, that framework has to be CLS compliant (“should be” is too soft in my view). And this means you cannot use generics on the public interfaces if you want to mark your assembly with the CLSCompliant attribute. The Non-CLS compliance of generics is pointed out in  and , with hints that generics will find their way into the Common Language Specification in the Orcas / Longhorn timeframe.
The Java developer. Now, how do they fit into the picture of the early adopter of .NET 2.0? I’m sure one thing .NET developers will hear a lot is that “Java had generics long before .NET.” Not so fast, Scotty. Just like there are differences between C++ templates and .NET generics, there are differences between Java generics and their counterparts in .NET. Once again, Anders Hejlsberg did a great job in  of explaining what is different: for one, .NET generics are actually typed, which means no boxing for value types (a very good thing!). Secondly, .NET generics are runtime too, not just compile time – you can reflect on generics in .NET, you can’t do that in Java. The lowdown: generics in Java spare you the task of casting, but that’s about it.
Finally, the group “Generics, huh?” Those are developers who for example still have the misconception that generics are a C#-only feature, like many programmers using 1.0 initially thought that features offered by the CLR were actually C# features. Let’s chalk that one up to miscommunication, but a repeated one.
You know that generics (will) exist, but have no clear idea what they are intended to be used for? I’d like to quote Anders Hejlsberg: “Generics is essentially the ability to have type parameters on your type.” D’accord? Really simple but really powerful.
You know what generics are (if not, please see the previous paragraph), but have no idea what to use them for? If you are like one of my friends “I’m not in the business of writing frameworks, and the .NET framework already has generic collections, so what use are generics to me?”, rest assured that there are plenty of other non-class uses: generic methods (data access, anyone?) and generic delegates (in an instant makes callbacks that much more fun). Did you know about those two generics use cases?
To conclude this editorial, I’d like to firmly state that generics are positioned somewhere between being “just a fancy way of replacing typed collections” and the all-too-powerful for shooting yourself in the foot C++ templates. Well designed, tightly integrated in the CLR, the right dose of power – with one problem: too many different views of what generics are, what they are intended for, and what they can be used for. I for one am confident that they will be useful to programmers – yes, useful – nothing more, nothing less.
 Generics in C#, Java, and C++
 How do C# generics compare to C++ templates?
 Generics Algorithms
 Dan Fernandez's Blog - Quick information on Generics
 Q&A with VJ# and C# Team on Generics
 An introduction to Generics
Bootnote: This blog entry originallly was intended to be an editoral, however, an editorial is an opinion piece, and the publisher wanted a different opinion. This is why the text is now in my blog where you can read (and flame) it freely.
|| Wednesday, 08 December 2004
Today we released yet another open source project: #usblib (SharpUSBLib). The history for this project is quite similar to many other OS projects ("scratching an itch"): Mike built a terrarium for his soon-to-be-delivered chameleon, and he wanted to manage the ligthing using a USB-controlled power switch. Not having found a suitable USB library for .NET, he decided to write one himself.
The library is used for low level access to USB devices, and it works under WIN32/.NET and Linux/Mono. Documentation can be found in the wiki, a support forum also exists. The download includes source code for this dual-licensed (GPL and LGPL) library.
|| Thursday, 25 November 2004
In case this weekend turns out to be too long for you (and you get bored without a real .NET challenge), check out the CodeDOM MSIL Code Provider and the CodeDOM Subset Code Provider. The more interesting bits from the download description:
The Microsoft Intermediate Language (MSIL) code provider takes a CodeDom tree and generates MSIL syntax. MSIL code provider generates all the CodeDom elements that are part of the 1.1 conformance spec. MSIL code provider generates code for most of the CodeDom types that shipped in V1.1. Why emit C# when you can emit IL!
The CodeDom Subset Code provider consumes CodeDom trees in the way the C# code provider does, but whenever a node that does not fall into the subset is encountered, it emits a #error in the generated code. This will alert to the CodeDom tree builder of any place in their code where they don't meet subset conformance. Roll your own subset of the C# language - anyone interested?
|| Tuesday, 24 August 2004
C5 is a library of generic collection classes for the upcoming version 2.0 of the .Net platform. C5 extends the standard .Net System.Collections.Generic namespace with tree data structures, heap based priority queues and hash indexed array lists and linked lists, making it more comprehensive than most collection class libraries on similar platforms. Unlike many other collection class libraries, C5 is designed with a strict policy of supporting "code to interface not implementation".
Now that definitely looks worth checking out!
© Copyright 2019 Christoph Wille
newtelligence dasBlog 2.3.9074.18820