Monday, December 14, 2009

InvalidComObjectException in UT

0 comments

If you are accessing COM server from UT in Visual Studio 2008 and get InvalidComObjectException exception.

Then try changing your TestRunConfig.testrunconfig:

image

 

add this line: <ExecutionThread apartmentState="MTA" />

Tuesday, December 1, 2009

MSXML2.DOMDocument.selectNodes vs. XDocument.Descendants

1 comments
OLD MSXML way:
MSXML2.DOMDocument xmlDoc = new MSXML2.DOMDocument();
MSXML2.IXMLDOMNodeList xmlList = xmlDoc.documentElement.selectNodes("//MyNodeName”);
 
LINQ way:
XDocument xDoc = XDocument.Parse(batchXML);
IEnumerable<XElement> commands = xDoc.Descendants(XName.Get(“MyNodeName”));

contactID = contactEl.Attribute("conactID").Value;
name = contactEl.Element("FirstName").Value;

Saturday, October 31, 2009

Can’t Debug inside some Classes ?

0 comments

Most probably it does not enter into auto generated classes(AltovaXML classes, …).

image

OR get rid of GeneratedCodeAttribute attribute.

Sunday, October 4, 2009

Implemeting IEnumerable<T>

0 comments

 

I always forget that there is something tricky when implementing templated IEnumerable.

IEnumerable<T>inherits from IEnumerable which has another method to cover.

So here is the example.

public class Sites : IEnumerable<Site>
{

    IEnumerator IEnumerable.GetEnumerator() { return theSites.GetEnumerator(); }
    public IEnumerator<Site> GetEnumerator() { return theSites.GetEnumerator(); }
}

Thursday, October 1, 2009

Danger: Events

1 comments

Before C# era, there were no such things as Events. But there were callbacks, ugly stuff to use. And now with C#, there are Events, comfortable, easy to use, subscribe, get notified from server, define event, fire it easy.

With C# there are 3 types of capabilities, class exposes:

Methods, Properties and Events.

 

Events=Methods with some extra subscription.

How do we decide, what Events are for and what Methods are for? More accurate question might be when to use Events and when Methods? The different between What and When might be the answer. Interested?

I think that the intention of Events is to let Client know WHEN something is done. This is a feedback, a follow up after Client was told WHAT to do.

And the intention of Methods is to let know Client WHAT to do.

So I try to consider these factors when defining Event and Method.

Friday, September 18, 2009

Navigating data cheetlist

0 comments

I’ll be adding here binding techniques that are useful and hard to remember. Happy navigating.

Map of London GPS-Tracking by photo808.

XAML syntax

binds to…

{Binding} current context
{Binding User} context.User
{Binding User.FirstName} context.User.FirstName
{Binding ElementName=editBox2, Path=Text} “Text” property of XAML “editBox2” control
{Binding RelativeSource={RelativeSource Self}, Path=User} User property of the target element
{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MyUserClass}}, Path=FirstName} going up in data tree until MyUserClass is met and going back down after FirstName.

More here.

Wednesday, July 1, 2009

to dispose Form or not: Not

0 comments

public void ShowForm()
{
    try
  
{
        MyForm form = newMyForm ();
        form.ShowModal();

    }
catch (Exception)
{
}finally
{


form = null



         or     


form.Dispose()   



}



}


I’ve seen that before. No need. Window.Close already disposes the form. And assigning the form to null might feel comfortable for C++ers but makes no difference in C# world.


Thursday, May 14, 2009

Creating Test Run Configuration

0 comments

Are you wondering where is my Test Run Configuration?

image

In order to create one, select solution, right click, create new item and this appears:

image

now you can create one.