#Google Analytic Tracker

Pages

Jan 20, 2008

Bad Error Message : System.IO.Filenotfoundexception in Visual Studio 2005 Designer

 

Have you ever use Visual Studio Form or User Control designer?

Have you ever run into construction error where the designer can't display your form?

Well, if you use Visual Studio, you would most likely have encounter error displaying your form if you:
A. manually manipulate the designer file (i.e. myForm.designer.cs)
B. you add runtime code to the form/user control's constructor causing your designer not to load.

Today, as I was working on my project, I don't know what I did to the code, but when I open my main form on the designer, Visual Studio crashed, and I got the following error:

image

At first, I thought it is something to do with the ActiveX control that I was referencing. I unregistered it and re-register it. No help at all. After I start playing around with my code by recreating my project, I found out what I did wrong.

It turns out that I add a System.Threading.Timer object to one of my user control's constructor. For example:

public partial MyUserControl : UserControl
{
//....
System.Threading.Timer myTimer = new Timer(DoSomeWork, null, 0, 180000);
//....
}

Since the user control is in any project, VS didn't crash until I rebuild the project and I reopen my main form that contains this user control. The confusing part is that instead of seeing error like the following, VS crashed and ask me to restart.

image

Hopefully the designer in Visual Studio 2008 will improve error handling and not crashing Visual Studio.

Jan 18, 2008

Select Statement for DataSet with Complex Data Type

I have been very busy with a lot of stuff, I almost forgot that I have a blog. This post will be my first post in 2008.

In the project that I was working with, we never use complex data type for our column in a DataSet (System.Data.DataSet). If you uses Visual Studio DataSet Designer, you will notice that the default DataType for your column are either .NET value type, string, TimSpan, Guid, DateTime.

What if you want to use your won DataType?

Surprising, the dataset designer works with custom data type. For example:

image

The Column DSTestTable1Key is using a custom data type calls "DataType.Key"

The Key data type is basically similar to a GUID, except it is not a restrictive as a GUID. If you try to create a GUID using random string value, it won't work.

I wrote a number of test to see if I can insert, update and data data row from the table. It works as expected, except how do I do select using this Complex Data Type?

It turns out that there is a function call Covert that you can use: For example:

   1: string l_sColumnName = UIModel.UIDataModel.DSTestTable1.DSTestTable1KeyColumn.ColumnName;
   2: string l_sExpression = "CONVERT([" + l_sColumnName + "], 'System.String')" + " = " +
   3:                        "'" + l_oNewRow.DSTestTable1Key + "'";
   4:  
   5: DataRow[] oResult = UIModel.UIDataModel.DSTestTable1.Select(l_sExpression);

What happen in the above example is that it convert the data type of my column data to System.String and than compare with my Key.ToString() value.

So in conclusion, as long as your complex data type support an override ToString() that is unique, you can use the above example to retrieve value based on your complex data type. To learn how more about the select express, see reference:

Reference: http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression(VS.71).aspx

Sep 8, 2007

In Love with ReSharper Again

 

It was awhile ago that I had given up on using ReSharper 2.5. Mostly it was due to its memory usage and performance.  I can't really blame ReSharper developers. This is party because the files and classes that I work with have over 1000 LOC (i.e. an indication of bad programming design).

However, after begging asking for more RAM from my team lead, I finally upgraded my computer to 3GB of RAM. In fact, my company was nice enough to pay for a license of ReSharper 3.0, C# version. Now I am back on more refactoring and making my code nice and clean.

Features that I like the most

Usage Search and Go to

Simple Visual Studio reference search is just isn't enough. Resharper provides many advance search functions to help you navigate and search your codes. For example. Shift + F12 bring you a list of references of your selected type, which can be sorted by projects, files, or namespaces. Alt + Home to jump to the type Base class, and Alt + End list all the Inheritor that you can go to.

Navigation is very important for me to analysis the unfamiliar code.

Importantly, Shift + Alt + F11, which highlight usage of your selected Type or Variable, which is similar to the Google search highlight, but it is search by highlight by usage, not text.

Refactoring

A powerful feature that ReSharper provides is Refactoring. Refactoring is a term that describes modifying the code without change its functionality. The goal of refactoring is to make the code easier to read, maintain, understand, and extent its function.

For example, using the "Move" refactoring function, I can move a class from one namespace to another namespace with a couple of clicks. Resharper will update the usages references for the rest of the code, so that you don't have to update them manually.

Code Correctness Check

The most attractive feature ReSharper has is that it constantly checks if your code is correct. If you are missing a variables, incorrectly passing parameter in different type, ReSharper would highlight the error for you, or warn you. So that you don't have to "try" compile your code to find out and fix your compiling error.

Other Features

Other Features like code completion, Resharper NUnit GUI, Live Templates are very useful.

Performance, Performance and Performance...

With 3 GB of RAM, I haven't encountered much performance issue as before. However, ReSharper still causes issue when I do the following:

  1. Dynamically generating a very large XML file - In my solution project, there is XML file that we store all the hardcoded string. The file is a couple thousand line of code. If you have this file opened, and use another program update its content, ReSharper would take a long time to parse.

    It appears that it would be faster for ReSharper to re-analysis the file instead of trying to updates its in-memory code.
  2. Renaming is slower than VS's Renaming function. If you have a type that is used in many places, using VS's Renaming is actually faster than using ReSharper. I am guessing Resharper has to updates its in-memory code by looping though code DOM, while VS simply find and replace using its reference search.
  3. Memory usage is high - even with 3GB of RAM, my devenv.exe still used up to 600MB (plus an other 600MB of Virtual Memroy).
  4. Get latest Visual Source Safe may causes Visual Studio to hang for awhile because ReSharper will reanalysis the code.

However, these performance issues are trade-off in the end, because ReSharper provides you instant update of the your code status.

I have been Trying to Convert Others

When I introduce this tool to my colleagues when I started working in the my company, I thought I bought a tool that would help them a lot. However, because of its performance, everyone of them uninstalled it.  I

I have tried to get them using ReSharping again after our computer is upgraded, but they still resisted. This tells me even ReSharper is a great product, first impression is very important. I did convert a new developer to use ReSharper :)

3.0 Improvements from Resharper 2.5

...that I experience

One thing I notice is that ReSharper is much more responsive. In the past, typing code while while Resharper is analysis code is painful and slow.  However, with 3.0, it seems like ReSharper stop analyzing while I type, which is much better.

I have encounter way less exception compare to 2.5. In the past, whenever I encounter an exception, ReSharper was bounded not going to work.

Conclusion

Resharper is by far the most intelligent tool that increase coding productive. I recommend C#, or VB developers should give it a try. Of course, it will help if you have more RAM in your computer.

BuzzNet tags: ,