April 29, 2008

Compiler complains about ‘Linq’

Filed under: Linq — Tags: , , — @ 6:37 am

I developed an application using VS 2008 and build on the box and everything was good. Now we were implementing the code compile in the CI environment. Where I installed .Net framework 3.5.

Now when I try to compile the code in Ci environment I get an error ‘Linq’ is missing. I checked assemblies and found System.Xml.Linq is in the GAC. I even added that as a reference to in the compile task. That didn’t resolve the problem. After some research I found out that, it looks like System.Linq is in System.Core.dll and even though it is in the GAC, we must explicitly include that as a reference during compile. Once I added that as a part of reference, the Linq error went away.

So, be careful on this.

CAB and Dynamic Menuitem generation

There comes a time, when you are developing CAB application you may need to insert menu items on the run. CAB comes with a feature to add the menu items from the app.config instead of entering each menu item in the shell itself. I rather keep it in the XML than in the shell, that way shell will continue to be shell. This out of box method also gives you a feature to associate command the required menu item click event as well.

If you are beginning to work on this item, I would recommend you to download Microsoft patterns and practices Composite Application Block Hands on Lab. This particular item was discussed in lab 3. If you follow the instruction in the lab you will understand how easy to add menu items dynamically from XML.

I would like to point out couple of things when you are adding the feature to your application;

1. Please remember to add the new section for ‘shellitems’ in the app.config. If you are wondering where it is used, it is used in the LoadFromConfig (UIElementBuilder).


NUnit in VS2008

Filed under: Tips and Tricks — Tags: , — @ 2:58 am

Even though VS2008 comes with Microsoft version of the unit testing, I still prefer NUnit. The real reason is one less to learn and on the other hand NUnit does gives me all the good things required for my TDD. I can imagine Microsoft test suite might give lot of nice integration with VS2008, NUnit can be integrated nicely to get what you want. There are third party tools you can buy that will integrate NUnit nicely into Visual Studio but I am not sure about VS2008 and if you are a person like me, I do not like to spend money on a tool if there is a way you can do it. By the way, if I spend money I spend it on book 🙂

My first approach and easy approach is to attach NUnit process to my Debug process and put break point in the line of code where I want to debug and everything goes well. Well, let me explain what I meant by this. Here are my steps, this can change based on your preference;


Building WPF application through console

Filed under: WPF — Tags: , , — @ 2:52 am

I build a simple WPF application using VS2008 and everything was ok. I needed to do little bit more outside the application (like adding a dynamic resource file to the WPF) so I decided to compile the application outside the IDE. I tried to compile it with the information provided in the MSDN page and it proved little difficult because of all the dlls I need to include during compile. So if you are like me trying to build WPF application through command line, the shortcut is, first build it through IDE. After the build is successful look at the output tab (at the bottom on the IDE), the first command is command line compiler call to build the application. So just cut and past it from there to a notepad or other editor where you would like to investigate what are all the required components for building the application.

Couple of things you have to remember, if you are going to compile the application from a location other than the project location, make sure all the source code files are converted to absolute path instead of relative path as in the IDE.

Once you make the change, now you can put it in a notepad and create a batch program and try running the batch program whola! you got yourself the exe.

Here is an excellent documentation on how to build wpf application from MS.

C# 3.0

Filed under: C# 3.0 — Tags: , , — @ 2:51 am

Recently I started using C#3.0 and I am loving all the new features MS has added to this fantastic language. One thing I was trying to do over time was to learn the functional programming. As you can imagine it is completely different paradigm shift. When I switched from COBOL to C++, I had to go through the same. Jumping from procedural to object oriented concept. It looks like with 3.0 there will be another shift I am very happy to do, jumping to functional programming, it is going to happen sometime soon for me. I wanted to learn functional programming while I thought it is going to take some extra effort from my side, C#3.0 kind of made my life easy by adding Lambda expressions in its arsenals. Now you all know why I am so hyped about 3.0. Enough said, let me go through what are the main new concepts added in 3.0


April 24, 2008

Finding a pattern in a string

Filed under: regex,Tips and Tricks — Tags: , — @ 7:52 pm

It is easier to use Regex to find the string pattern you are looking for in a string using C#. If you are not sure how to use them, please use this link.

If you are trying to find a string with control characters please remeber to use ‘\’ character in front of it. Most of the time, you may not be looking for a string with special characters in it. If you are then make user you use correct character.

For example, I have a string x = “$\John\Mary”

I need to replace $\John\ with say blank, I want only Mary from that string. Then you need to do the following

string result = Regex.Replace(x, @”/$/\John/\”, “”);

With this each control character is preceded by / so that, regex will use that as a normal character otherwise, regex will try to interpret them as special character and you will not find the match.

Finding string from an array

Filed under: Linq,Tips and Tricks — Tags: , , , — @ 2:26 pm

I ran into a situation where, I need to find a string from a string array where I know only the part of the string I am looking for. So if I would be writing the code in C#2.0 the code would be something like the following;

string[] array = {“help”,”Csharp rocks”,”I am learning”};

string findString = “rocks”;

string matchedString=””;

foreach(string str in array)


if (str.Contains(findString))


matchedString = str;




if (matchedString.Length > 0)


// the code to handle the logic goes here.



Powered by WordPress