Galin Iliev's blog

Software Architecture & Development

C# 3.0 Compiler milestones

Luke Hoban, Program Manager for the C# Compiler posted blog article how is schedulled job for C# 3.0 compiler. This show what are new things and when we could expect to touch them:

Milestone 1

Our first goal was to get the most fundamental new language features implemented, so we could begin building LINQ applications with the Orcas compiler as early as possible.  Many of the features in this first set were also chosen because they were pre-requisites for implementing some of the later language features.  For example, lambdas were important to get in early, because the conversion of lambdas to expression trees depended on this.  Here's what we built first:  

  • Local Variable Type Inference (var)
  • Lambdas
  • Object Initializers
  • Extension Methods (usage)

Milestone 2

For our second milestone, our goal was to replace the C#3.0 prototype compiler that we had shipped with the May 2006 CTP.  When we finished this milestone, we actually moved all of the teams internally who were using C#3.0 over to use the Orcas C# compiler.  This required implementing:

  • Lambdas bound to Expression Trees
  • Extension Methods (definition)
  • Collection Initializers
  • Anonymous Types
  • Query Expressions

Milestone 3

The third milestone was shorter, and our goal for this milestone was to get to a good state for the first Beta.  The results of this milestone are what you'll see in the Orcas February/March CTP and the first Orcas Beta.  We also implemented one of the most requested language features in the history of C# - auto-implemented properties!

  • Auto-Implemented Properties
  • Enhancements to Collection Initializers
  • Non-language features, such as debuggability improvements

Milestone 4

We're now working on the last feature milestone for Orcas.  We're finishing off with one more language feature and a lot of work to improve compiler fundamentals, such as error messages and performance.  Note that this work won't make it into the first Beta:

  • Partial Methods
  • Compiler Error Message Improvements
  • Compiler Performance
  • Compiler Generated IL Performance

It seems most of the features are implemented and we could see them in CTPs. We can touch most of them except Partial Methods. It looks like MS shaped the main VS Orcas features and they will shine them in next months before they release version 9.


Windows Forces you to use UAC to Add a Printer

I've been using Vista since beta 2 but I haven't had my network printer installed up to now.

Everytime I tried to install network printer I get the message saying: "Windows cannot connect to the printer. The specified print monitor is unknown." with the following screen.

I finally found solution on this here and here.

Simply said if you're in same situation then you must turn on UAC. Yes, you need UAC in order to install network printer. Once installed you can turn it off again.

Here was some intersting suggestion from javmirin:

In Vista PC's go to "Control Panel" - "Printers" - "Add printer".
Believe or not, click "Add a local printer" (I know you want to add a network printer but that way it doesn't work).
Click "Create a new port" - "Local Port" - "Next"
In the next box you have to enter a port name like this:
\\PC name\Printer name
where "PC name" is the network name of the XP PC where you have the printer and "Printer name" the network name of that printer. Be careful with this names. Check in your XP PC "Control Panel" - "Printers and faxes" - "your printer" - right click - "share" - "share resources name"
(sorry I'm translating from Spanish and not sure these are the exact terms).



Visual Studio Codename "Orcas" timetable

Visual Studio Codename "Orcas" timetable was released on MSDN2.

Here is it:

Visual Studio code name "Orcas"

In addition to developer productivity improvements and new supported platforms and technologies in Visual Studio, Visual Studio code-named “Orcas” release will include the following new scenarios, features and improvements to Visual Studio Team System.

Projected Availability:

  • Beta 1 - 2nd Quarter, CY 2007
  • Beta 2 - Mid-year CY 2007
  • RTM - TBA

It seems we will have more stable releases soon :)

C# architect Anders Hejlsberg does ... VB on MVP summit

I came across Jim Wooley's blog where C# architect Anders Hejlsberg does demo with VB. :)

I find this very interesting and I decided to share with you :)

I have nothing against VB (except a few thigs :) ) and I do VB from time to time because of specific tasks. The biggest VB advantage against C# is optional parameters. To do this in C# you will have to declare buch of methods overloads.

I don't want to turn this into discussion which one is better. I just find interesting Wooley's post Anders does VB!

Protect your ASP.NET website from DoS attack

DoS is not Disk Operating System :). This stands for Denial of Service attack and briefly described is when to many calls are made to your service so it stops responding to intented users/customers. for more info see Wikipedia.

MS MVP Omar AL Zabir wrote good blog entry about how to prevent DoS attacks on ASP.NET sites and expecially web services.

When you make good ASP.NET application and clear most of the bugs (yep nobody is perfect) it is time to adjust it to be high available and fast respondible Prevent Denial of Service (DOS) attacks in your web application is good start to protect your creation from so called hackers attacks :)


Enable RibbonX intellisense in Visual Studio

I had interesting experince with customizing Ribbon within VS 2005.

At first place I was able to get very helpful intellisence in VS IDE. After some time I had to edit .xml fiel but... no intellisense. well ... what to do?!

I intalled VSTO - I didn;t have it after last reinstall. and bingo - I've got it again... until today...

What happened?! Why?!  I just don't know - (probably most of us hears customer, friends and relatives that phone us with strange PC question and says - Yesterday it worked and I haven't touched anything! :)  ) Same thing here :)

But I know how to enable that intellisense again. And this is how:

  1. You need customUI.xsd and Visual Studio 2005 :)
  2. place customUI.xsd in %programfiles%\Microsoft Visual Studio 8\Xml\Schemas  and this is it. You must have it.

There are some other ways to enable intellisence for xml in VS 2005. You can find them on Aaron Stebner's blog post.

2007 Office System Document: Lists of Control IDs

In new MS Office sysem 2007 is possible to target existing ribbon controls by using idMso="ControlId".

The question here is: How can I find existing control id?

Microsoft assisted to us and put them here. This is archive with Excel files with all controls ID and location description separated per application.

For non-office developers this could be also very interesting... because... well at least you can find how many ribbon controls are in certain application :)

  • # Excel Ribbon controls - 1732 rows
  • # Powerpoint Ribbon controls - 1573 rows
  • # Word Ribbon controls - 2602 rows

This shows how big became MS Office for all these years and explains why it is difficult to know. You guys didn;t think MS Office is easy, did you? :) 

For more details download 2007 Office System Document: Lists of Control IDs

Connection pooling and application domains

Yesterday I wrote about my Connection pooling tests and I had good comment from Marto Kulov about application domains.

It was easy so I wrote the following code to create new application domain and execute two forms from different assemblies in order to test if they share same connection pool


   1:  AppDomain domain = AppDomain.CreateDomain("myNewDomain");
   3:  Form frm1 = domain.CreateInstanceFromAndUnwrap("WindowsApplication1.exe", "WindowsApplication1.Form1") as Form;
   4:  Form frm2 = domain.CreateInstanceFromAndUnwrap("WindowsApplication2.exe", "WindowsApplication2.Form1") as Form;
   6:  frm1.Show();
   7:  frm2.Show();

And the answer is Yes, They share same connection pool. Both forms executed same for loop and opened 10 connections each to the MS SQL Server. And on the SQL Server side was only one connection alive.

So this is the way to share a connection pool between two processes - put them in one process and in one application domain.



Connection pooling

Two days ago I decided to dive into connection pooling secrets. What a coincidence with Sahil Malik as he wrote blog article about his research same day J.

In addtition to his article I can describe what I tested. As I have job to do I will miss screenshotsL.

We were considering option to pass data to SQL SPs usign connection string and we wanted to know how this affects connection pooling. So I created simple winform application with a button with the following.

   1:  string connString = @"data source=.\SQLExpress;
   2:                      user id=gu; password= 123; 
   3:                      Initial catalog = master;
   4:                      Workstation ID=test_host{0};
   5:                      Pooling=true;
   6:                      Connect Timeout = 60";
   8:  for (int i = 0; i < 10; i++)
   9:  {
  10:      SqlDataReader dr = null;
  11:      string cmdText = "SELECT date=getdate()";
  12:      SqlConnection cn = new SqlConnection(string.Format(connString, 1));
  13:      SqlCommand cmd = new SqlCommand(cmdText, cn);
  14:      try
  15:      {
  16:          cn.Open();
  17:          dr = cmd.ExecuteReader();
  18:          if (dr != null)
  19:          {
  20:              while (dr.Read())
  21:              {
  22:                  Console.WriteLine(dr["date"].ToString());
  23:              }
  24:          }
  25:      }
  26:      finally
  27:      {
  28:          if (dr != null) dr.Close();
  29:          cn.Close();
  30:      }
  31:  }

I used same SQL statement as Sahil to determine number of physical connection to database.

After executed the following code I got only one connection opened. Note that connection string is always same as I pass 1 as parameter in string.Format(connString, 1) on line 12.

Let’s change this to string.Format(connString, i). As expected I ended with 10 opened connections as connection string is different for every SqlConnection object.

Let’s undo change and use connection pooling again. We have for loop with 10 connection objects opened but only one physical connection is opened on SQL side.

Let’s start two instances of our test application and check what happens by clicking on buttons. We executed for loop once in each instance. By executing Sahil’s SQL statement we see two connections  although all 20 connection has same connection string.

I opened Activity Monitor from SQL Management Studio and I was able to see the connections – everything was same except Net Address. According the documentation:

Net Address

Assigned unique identifier for the network interface card on each user's workstation. When the user logs in, this identifier is inserted in the Network Address column.

Strang… both instances are on same machine…

So as conclusion the statement from Wikipedia’s Connection Pooling page – “A Connection Pool is a cache of database connections maintained in the database's memory so that the connections can be reused when the database receives future requests for data.

Is wrong… the pool is only on client side

As I missed the screenshots I will add another example in case I lost you somewhere above J

Connection pooling is pool of connection within instance of application! If you have two instances of same application that creates one connection to SQL  Server you will have 2 conenction to the server.

If these 2 instances created 20 connections each (with same connection string within the instance) there will be 2 connections on the server because connection pooling.

If these 2 instances created 20 connections each (different connection string each) there will be 2x20=40 connections on the server because connection pooling is done only on same connection string. 

Count to 31 using one hand.

Probably this is not big deal but it is interesting so I decided to share with you.

All of us are supposed to know how to count to 5 using one hand. But can we count above  5? How?!

Think about this for a while :) 

(if you want to give up and just to see solution check here)