DataRow.SetParentRow Method

I’ve noticed an existence of DataRow.SetParentRow Method.
MSDN documentation is quite brief: Sets the parent row of a DataRow with specified new parent DataRow.
It wasn’t clear does the functions fills foreign key values in the child row from the parent one.
Thanks to Reflector, I confirmed, that it does SetKeyValues .
Please note that from performance point of view it is important to call SetParentRow first and add the childRow to the child table later..

XmlChoiceCollection class to access XSD generated properties for choice XML elements

When I used XML Schema Definition Tool (Xsd.exe) ,  it creates proxy class with extra ItemsChoiceType array and enum for xsd:choice  elements. 

MSDN XmlChoiceIdentifierAttribute Class article shows example of XSD, generated proxy class and how to fill  pairs of arrays:

// Populate an object array with three items, one

      // of each enumeration type. Set the array to the

      // ManyChoices field.

      object[] strChoices = new object[]{“Food”,  5, 98.6};


      // For each item in the ManyChoices array, add an

      // enumeration value.

      MoreChoices[] itmChoices = new MoreChoices[]





I found that support two arrays for items itself and for EmlementNames is error prone and created helper generic XmlChoiceCollection class, that allows to add items and types inone Add method.


#region  Namespace Imports

using System;

using System.Collections.Generic;

using System.Text;

#endregion  //Namespace Imports


    /// <summary>

    /// see

    /// </summary>

    public class XmlChoiceCollection<TItem,TItemsChoiceEnum>


        public List<TItem> _items;

        public List<TItemsChoiceEnum> _elementNames;

        public XmlChoiceCollection()


            _items=new List<TItem>() ;

            _elementNames=new List<TItemsChoiceEnum>();


        public void Add(TItem item, TItemsChoiceEnum elementName)





        public TItem[] ItemsToArray()


           return   _items.ToArray();


        public TItemsChoiceEnum[] ElementNamesToArray()


            return _elementNames.ToArray();




Example of use:
XmlChoiceCollection<MyElement, ItemsChoiceType> choiceCollection = new XmlChoiceCollection<MyElement, ItemsChoiceType>();
for (int i = 0; i < Count; i++)
   choiceCollection .Add(new MyElement(), ItemsChoiceType.type1);

request.Items = choiceCollection.ItemsToArray();
request.ItemsElementName = choiceCollection.ElementNamesToArray();


Shortkey Alt-B,U is ambiguous in Visual Studio 2008 team edition


In Visual Studio I like to use shortkey Alt-B,U to start build of the current project.
However in VS 2008 team edition it doesn’t start the build, but just opens menu and waits for extra “Enter” click.
The reason is that on the Build menu,there is extra “Queue new build” menu item with the same u shortcut, which conflicts with “Build Project”  menu item.
The issue reported to MS Connect and they told, that it is fixed in a future release.
Is it possible to change alt shortkeys for standard menu items?

I know that I can assign new shortkeys using Customize, but my hands need  to remember this new key, and my preference is to hide-disable  shortkey for “Queue new build” , which I am not using anyway.

QuickCode.Net 2008 new TAB shortcut key

QuickCode.Net  has a new free 2008 version.

UPDATE: in a new release 3.0.6. it’s possible to assign any shortcut key. In VS 2008  Customise keyboard  I’ve selected command QuickCode2008.AddIn.ReplaceQuickCode  and assigned a shortcut key Alt-Q.

It uses <TAB> instead of previously assigned Alt-Q hotkey.

<TAB> is consistent with standard VS snippets.

 If you press the TAB key after your QuickCode, e.g.


the QuickCode will expand.

If the same pattern exists in snippets and QuickCode, the VS snippet goes first. QuickCode deliberately does NOT expand QuickCodes while Intellisense is active.

After some use of new QuickCode.Net 2008  I understood that I prefer old Alt-Q , not new Tab


 The reasons for this are the following:
1. when typing, because of active Intellisense list it usually requires to do <ESC> to clear list , and only then <Tab> , instead of simple <Tab>
2. To clicking <Tab>, you need to be at the end of line.
E.g. if you typed your macro and want to fix typo in the middle of the line , you neet to go to the end of the line next.
Alt-Q didn’t have this requirement.
3. Parameter with spaces doesn’t work with TAB.
E.g. I have a macro
#r Region description with spaces
that converts into
#region  “Region description with spaces”
#endregion  //”Region description with spaces”
It worked with Alt-Q, but when using TAB, spaces within parameter are not supported.
UPDATE: Markus from (MOBZystems) adviced me to use Optional arguments:
To support spaces In the following QuickCode macro in the pattern use :  not
#r %%desc%%
#r %{desc}%.
<?xml version=”1.0″ ?>
<quickcodes version=”3.0″>
  <quickcode description=”region” pattern=”#r %{desc}%” priority=”0″>
    <expansion language=”Basic”><![CDATA[#region “%%desc%%”
#End Region ‘ %%desc%%]]></expansion>
    <expansion language=”CSharp”><![CDATA[#region “%%desc%%”
#endregion // %%desc%%]]></expansion>
And everything works as expected!
 Tip: You can copy the XML above to the clipboard and paste it into the QuickCode list to copy this QuickCode to your own collection.

Ideally it would be good if QuickCode  will support both keys. 

Related link(s):

My older post: QuickCode commands file location


“Login failed for user” may mean “database name is invalid”

One of my colleagues tried to work with a new database from DevServer and got an error “Login failed for user”.
We checked everything related to security and permissions, but it didn’t help.
After a while we recognize that there was spelling mistake in the name of the database in connection string.
In this case  Login failed for user” error actually meant  “database name is invalid”
Why it wasn’t shown as a reason in plain English?
Other possible reason for the errors are described in multiple articles, including following:

Generate C# class from XSD file.

I have an existing C# file, generated a long time ago from XSD definition.
The XSD files were changed, and proxy class should be regenerated.
I’ve tried to use XML Schema Definition Tool (Xsd.exe) to generate C# class, but it  returned the error: “The datatype is missing”.
I’ve actually have two XSD files -outer and imported
Thanks to the post: XSD.exe is kicking my butt, man…redux , it pointed me to specify all necessary files on the commandline.
Note that name of generated file is combined from the files listed
I’ve created the batch file to be able to rerun it  
@call “C:Program FilesMicrosoft Visual Studio 8VCvcvarsall.bat” x86
xsd.exe outer.xsd imported.xsd /classes /l:cs /n:MyNamespace

rem rename  outer_imported.cs as outer.cs 

By some reason the generated file created in some non-default encoding, which inserts 3 characters

 in the beginning.It is a minor annoyance, but when I delete them, VS shows me a warning, that wrong encoding could prevent keeping history.
The next issue was that the new XSD(.Net Framework 2.0 and 3.5) generates C# classes differently with what 1.0/1.1 XSD.exe did.
In a few places 1.1 version generated custom collection of objects, but new XSD.EXE generates array of objects, so I have to change the calls to generated classes.

Another problem with XSD generated classes is that it disables  step into debugging even on methods that you  extended in partial classes by specifying DebuggerStepThroughAttribute for classes. Workarounds are described in XSD.exe and DebuggerStepThrough post.  Issue reported to MS Feedback.

I should try An XSD to .NET language code class generator that adds real punch to Microsoft’s XSD Tool.
or Sample Code Generator

Another issue was that authors of XSD file added   xsd:choice  elements and it creates extra ItemsChoiceType array and enum.I described how I addressed it in my post XmlChoiceCollection class to access XSD generated properties for choice XML elements


That’s pity, that minor changes in XSD file causes different class properties to be generated and essential code  changes to access the new properties.

Visual studio 2008 “Build action” properties: Shadow and CodeAnalysisDictionary

I’ve noticed that in Visual Studio 2008  files have additional “Build action” properties: Shadow and CodeAnalysisDictionary.
I’ve tried to find their meaning on Google but without success.
Does anyone know,what they suppose to do?

Disk Cleanup Utility should delete temporary .Net files.


I noticed that one of our servers with low disk space had a lot of  security.config.cch files(or security.config.cch.number) in individual user folders, as well as in .Net.Framework config directories.

According to the thread -it seems they are safe to delete.

But why they are located in config folder, not in some temporary directory, like
NETFramework{version}Temporary ASP.NET Files folders?

And they should be suggested for deletion by standard MS windows Disk cleanup utility.

I’ve submitted this suggestion to MS Connect

Links:How to save html file to PDF

I want  to save html file generated by ASP.NET to PDF.

I was pointed to itextsharp open source project.

I found a few links, discussing how to do it:

 iTextSharp Tutorial Chapter 7: XML and (X)HTML

 iTextSharp Demo( 2.0): introduces HtmlParser.Parse.(see the source code here)

We tried to use it.

HtmlParser.Parse does NOT throw any error , but the pdf file generated from this could be blank/empty.
Debug output shows the messages from parser, if Html file has invalid structure.

This is a big problem: HtmlParser.Parse is very strict and any minor mistakes in HTML causes exceptions or almost silent creation of empty PDF file.

The post of Creating pdf in .NET from html has a lot of interesting comments, including suggestion  to use HTML Agility Pack.

We are going to try how HtmlParser.Parse will be tolerant to html, regenerated from HTML Agility Pack.

The thread   [ 1819614 ] Error parsing images in HTML files has description of the fix

Another option is always use XML complient HTML, verified by ,but it could take some time to tidy up the HTML generated from ASP.NET

 Links to other products:  

Generate PDF from ASP.NET gives a few references to different products including iTextSharp

 Dynamically Generating PDFs in .NET : 

 Another option is to try (and possibly buy) commercial product abcpdf 


I saw a suggestion to use -the command line version of HTMLDoc to convert HTML to PDF, but it is not good for programmatic access.


Call Synchronous Web Services Methods Asynchronously

I need to asynchronously call a few web services at the same time.
VS 2005/2008 Web services proxy  generator creates several proxy class methods , including
synchronous MyWebMethod(parameters) and asynchronous pair BeginMyWebMethod(parameters) and EndMyWebMethod(parameters)
The way to use Begin/End methods is described in article “Calling Web Services Asynchronously ” 
Even if I am going to use asynchronous method in the real application, for unit testing(including TestHarness ) it is much easier to start with synchronous version. 
Correct population of all  input parameters and reading response can take some time for coding/debugging(if the web service method is not trivial).
Usually this code wrapper implemented as a separate function (e.g. CallMyWebMethod) in your client application.
If you want to use asynchronous pair , your will need to duplicate the wrapper functions as BeginCallMyWebMethod , that will filled request data and EndCallMyWebMethod function, to read and interprete response.
I found that it is simpler to use ability to call Synchronous Methods Asynchronously (using delegate invoke) directly in your code rater than use pre-generated Begin/End pair.
// call the service.

MyClass.ExecuteDelegate requestDelegate =new MyClass.ExecuteDelegate(myRequest.CallMyWebMethod);

MyAsyncState asyncState =new MyAsyncState (myData);

IAsyncResult asyncResult= requestDelegate.BeginInvoke(null, asyncState);

 //and when call will be completed

 AsyncResult asyncResult=(AsyncResult)ar;

MyClass.ExecuteDelegate requestDelegate = (MyClass.ExecuteDelegate)asyncResult.AsyncDelegate;

 MyResponseClass myResponse =(MyResponseClass )requestDelegate.EndInvoke(asyncResult); 

In this case the actual custom  application code of CallMyWebMethod function stays unmodified for both sync and async execution.

Similar approach was described in my old post Asynchronous long-running tasks in ASP.NET application