Galin Iliev's blog

Software Architecture & Development

C# 4.0 vs Visual Basic 10

This is how close will become C# and VB in next release:

C# 4.0 Visual Basic "10"
Named/Optional Parameters Named/Optional Parameters
Dynamic Scoping Dynamic Scoping
Statement Lambdas Statement Lambdas
Multiline Lambdas Multiline Lambdas
Auto-Implemented Properties Auto-Implemented Properties
Collection Initializers Collection Initializers
Generic Variance Generic Variance
Extension Properties Extension Properties

The items in white-bold are new features…

(Source: PPTX from VS2010 and .NET Framework 4.0 Training Kit)

MSBuild resources

MSBuild is very powerful language for automating build process but as every computer thing it could be confusing.

So for a start this should work as Visual Studio solution files (*.sln/*.proj) files are valid MSBuild files:

MSBuild MySolution.sln

So for more script-like example this can show how complex solution with Web Application project can be build and files (result of publish operation) copied to drop location.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns= 
  <Target Name="Clean">
    <Exec Command="MSBuild.exe WcfFileTransfer.sln /t:Clean" />
  <Target Name="Build">
    <Exec Command="MSBuild.exe WcfFileTransfer.sln /t:Rebuild /p:Configuration=Release 
/p:OutDir=..\$(OutputFiles)" ContinueOnError="False" />

      <!--include needed files-->
      <WebFiles Include="$(PrecompiledWeb)**\*.*"
    <!--show message-->
    <Message Text="Copying to Deployment Dir:@(WebFiles) to $(ReleseFolder) :" />
    <!--perform recursive copy-->
            DestinationFiles="@(WebFiles->'$(ReleseFolder)\%(RecursiveDir)\%(Filename)%(Extension)')"  />

This script is executed from Visual Studio Command Prompt like this

MSBuild build.proj

For more information  about MSBuild you can take a look at MSDN reference page or Channel9 Wiki:

* Project File Format
* Shipping Tasks
* Loggers
* Tasks
* VS / Integration
* Conversion
* MSBuild.exe Command Line
* Object Model
* Scenarios
* Does Microsoft use to build its own products?
* How to execute CS templates from MSBuild?
* External Links and Resources
* Quick Start Tutorials
* Write a simple project
* Clean my Build
* Specify which Target to Build First
* Build All Files in a Directory
* Build All Files in a Directory Except One
* Build the Same Sources with Different Options

* Use Environment Variables in a Build
* Check whether an Environment Variable has been set
* Build a Project with Resources
* Build Incrementally
* Use the Same Target in Multiple Project Files
* Tell to Ignore Errors in Tasks
* Extend with a New Task
* Build a Set of Dependant Projects
* Run a Custom Tool From my Project
* Specify Several Build Options on the Command Line
* Use Reserved XML Characters in Project Files
* Display an Item List Separated with Commas
* Convert an Item List into a scalar string
* Reference the Name or Location of the Project File in the Project File
* How do I do a recursive copy?
* Batching Examples
* MSBuild Specifications
* How the batching algorithm works
* How to find targets files in a canonical place

Or the MSBuild: By Example tutorial:

  1. Introducing Well-Known Metadata
  2. Formatting Your Output
  3. Editing MSBuild Files with IntelliSense
  4. Integrating MSBuild into Visual Studio
  5. Introducing Custom Metadata
  6. Understanding the Difference Between @ and %
  7. Using Environment Variables in Your Project
  8. Reusing MSBuild Project Elements
  9. Dealing with MSBuild Errors

I hope this is good as a start.

It’s playtime… with C# 4.0

After being quite busy for last 4 months it is a time to ramp up with new cool technologies that are on the product line.

So while installing VS 2010 it is a good reading to find out what to do once it is done:

And of course get some free time – a night or two should be enough :) should be enough for starting…

x64bit Development with .NET

Today the hardware is cheap (and getting cheaper) so it is easily affordable to have multiple quad code CPUs, 8 GB RAM and more. In order to fully utilize this hardware x64b OS is needed and Windows has x64b editions for a while.

But what happens with the software we write?! if you use managed code only then is easy – IJW – It Just Works (do you remember that term for compiling unmanaged code C++ into IL? well that’s different)

As MSDN article “Migrating 32-bit Managed Code to 64-bit” says

Consider a .NET application that is 100% type safe code. In this scenario it is possible to take your .NET executable that you run on your 32-bit machine and move it to the 64-bit system and have it run successfully. Why does this work? Since the assembly is 100% type safe we know that there are no dependencies on native code or COM objects and that there is no 'unsafe' code which means that the application runs entirely under the control of the CLR. The CLR guarantees that while the binary code that is generated as the result of Just-in-time (JIT) compilation will be different between 32-bit and 64-bit, the code that executes will both be semantically the same. (You cannot install the .NET Framework version 2.0 on Windows 2000. Output files produced using .NET Framework versions 1.0 and 1.1 will run under WOW64 on a 64-bit operating system.)

If you want to dig into x64 vs x86 differences read Scott Hanselman’s article “Back to Basics: 32-bit and 64-bit confusion around x86 and x64 and the .NET Framework and CLR

Also check Brian Peek’s blog post on the subject

Application Architecture Guide 2.0

“To deal with the many technology additions since then, J. D. Meier and his team from Microsoft patterns & practices have created a new application architecture guide to provide insightful guidance for designing .NET applications based on the latest practices and technologies. The outcome is Application Architecture Guide 2.0, a guide targeted to help solution architects and developers design effective applications on the .NET platform. The guide gives an overview of the Microsoft .NET platform and the main technologies and capabilities within it. It provides not only principles-based guidance, but also platform-independent, pattern-oriented guidance for designing your application. Even though the guide itself is comprehensive on its own, the team has also provided a Knowledge Base on the Web, which provides informative expansion on the topics and concepts outlined in the guide.”

Forewords by Scott Guthrie
Corporate Vice President of .NET Developer Platform

Go grab it or read online @

Time for reinstall&hellip; .NET Framework

I had interesting issue today: I was on urge to complete a task when I saw a strange exception – you know – the Murphy's law. It hit at the most inconvenient time. To be even more interesting I’ve deployed my work on two different servers and worked fine.

But on the most important one I got this exception when I tried to hit WCF service:

System.MissingMethodException: Method not found: 'Void System.ServiceModel.Diagnostics.EventLogger.UnsafeLogEvent(System.Diagnostics.TraceEventType, System.ServiceModel.Diagnostics.EventLogCategory, System.ServiceModel.Diagnostics.EventLogEventId, Boolean, System.String[])'.
   at System.Runtime.CompilerServices.RuntimeHelpers.PrepareDelegate(Delegate d)
   at System.AppDomain.add_UnhandledException(UnhandledExceptionEventHandler value)
   at System.ServiceModel.ServiceHostingEnvironment.EnsureInitialized()
   at System.ServiceModel.PartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
   at System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Very strange… and search engines doesn’t know much about the problem…

Luckily this was not used heavily and I could reinstall .NET Framework 3.5. And this solved the problem.. Now back to more productive things…

ASP.NET Adjust HTML Size, UX and AJAX

Problem Introduction

You come up with a great HTML layout for data-driven ASP.NET web page which makes perfect sense from business perspective and reveals key indicators while making possible to drilldown into details if needed. This page utilizes DHTML and AJAX calls to improve User eXperience (UX) and overall page looks great until… your database is not filled up and page load time is increasing due to generated HTML size, DHTML is slow due to big DOM tree and users starting to complain about it.

Possible Solutions

At that point there are several approaches that can be employed to help:

  1. Rework page layout so only part of data is loaded;
  2. Download data to the client in XML or JSON format and generate necessary HTML code on client
  3. Load only those portions that need to be immediately displayed and load others on demand (e.g. like paging)

Let’s explore these options:

Rework layout

Here is no technical challenge here – just business one: you have to sell new layout to existing users/customers and once they liked the initial one this can be really difficult. If you can do that – go ahead. There is nothing wrong with that approach.

Client-side bindings

Instead of downloading 10 MB HTML code to client’s browser you can generate pure JSON and having a template of HTML just to fill data in the HTML template with simple (or not-so-simple) loop. Good news here is that such feature is coming to ASP.NET AJAX in v4.0. It is called client templates and implements the idea. Here are some resources:

Partially Loading Page

This is also not new concept – load only  those parts that should be visible immediately to the user. Traditional paging explores that option although it is not that fancy. If you’re using Google Reader you probably noticed that it loads only visible part of the feed and as you scroll down it keeps loading from the RSS feed.

So here is the idea: having small piece of HTML loaded would ease the browser in rendering HTML DOM tree and you gain performance. As user keeps using the page you keep adding HTML to existing DOM tree by loading it dynamically using AJAX.

Tricky part could be rendering ASP.NET User Control within Web Service so pure HTML can be returned by AJAX. Here are some useful tips:


Utilizing these techniques could improve download time for your web apps and also speed them up because the browser doesn’t need to process whole DOM before give the control to the user. All these can be used together or in any combination as long as it makes sense from business perspective.

Hope this helps!

VS2008 Web Setup Project and Win2008

I had interesting experience today. I tried to create a web setup project for one of my recent projects. As you know it is pretty straightforward: From Visual Studio 2008 File –> Add –> New Project –> Select Setup wizard.


and just add output from existing project.
Then press Ctrl+Shift+B (Build ) and you’re ready… But not in Windows Server 2008. When I decided to test this newly made installation package I hit the ground with single dialog showing this message:

"The installer was interrupted before ApplicationName could be installed. You need to restart the installer to try again.

Click "Close" to exit."


Being experienced installer package developer I knew what I had to do: run the installer with verbose logging.

by executing this line:

   1: msiexec /i Installer.msi /lv detail.log

And I had nice 57 KB  file to read in wonderful notepad. And the problem action quickly appeared:

   1: Action start 16:22:53: WEBCA_SetTARGETSITE.
   2: MSI (c) (B4:4C) [16:22:53:082]: Note: 1: 2235 2:  3: ExtendedType 4: SELECT `Action`,`Type`,`Source`,`Target`, NULL, `ExtendedType` FROM `CustomAction` WHERE `Action` = 'WEBCA_SetTARGETSITE' 
   3: MSI (c) (B4:48) [16:22:53:082]: Invoking remote custom action. DLL: C:\Users\ADMINI~1\AppData\Local\Temp\MSIFB61.tmp, Entrypoint: SetTARGETSITE
   4: INFO   : [11/11/2008 16:22:53:097] [SetTARGETSITE                           ]: Custom Action is starting...
   5: INFO   : [11/11/2008 16:22:53:097] [SetTARGETSITE                           ]: CoInitializeEx - COM initialization Apartment Threaded...
   6: ERROR  : [11/11/2008 16:22:53:097] [SetTARGETSITE                           ]: FAILED:    -2147221164
   7: ERROR  : [11/11/2008 16:22:53:097] [SetTARGETSITE                           ]: Custom Action failed with code: '340'
   8: INFO   : [11/11/2008 16:22:53:097] [SetTARGETSITE                           ]: Custom Action completed with return code: '340'
   9: Action ended 16:22:53: WEBCA_SetTARGETSITE. Return value 3.
  10: MSI (c) (B4:4C) [16:22:53:097]: Doing action: FatalErrorForm
  11: Action start 16:22:53: FatalErrorForm.

Seeing WEBCA_SetTARGETSITE means that the installer was trying to set the destination. Having a web setup this means IIS was asked for “Default Web Site” and this call must be the one that fails. But why!? I have Web Server Role installed on the machine:


I and remembered from my MS DevDays 2008 IIS talk  – you still can use old (pre v7) IIS management tools with IIS7 as long as you have “IIS 6 Metabase Compatibility” role service installed.


I installed this role and … Voila!!! it works!!!