Friday, October 03, 2008

I passed 70 502 MS WPF Exam today, scored 873. It is not a very pretty score comparing to my 1000 for 70 536, but pass is a pass

Even though it took almost 2 hours to complete all questions and review a dozen marked ones, I think it is a reasonably easy exam.

I reckon the sectional results (evaluating the strength of each area) is quite spot on, it shows exactly those weak area of my knowledge.

In terms of my preparation, apart from doing WPF at work for the last six months, I did spend some spare time studying the MSDN. But that is it, I did not use any WPF books.

Sunday, April 06, 2008

I went to Mrs Macquarie's Point today, and checked out the 1st Reb Bull FLUGTAG Sydney. It was so much fun.
It was all about rather stupidity than intelligence. :) It didn't give me wiiings, but it brought me plenty laugh.
There were almost 30000 people turned up to the event. For a city like Sydney, with not so big population, this is a very good marketing campaign by Red Bulls. As I can remember, the last time I saw this many people was when the Queen Mary 2 & QE2 met in Sydney harbor in 2007.

Saturday, April 05, 2008

If a Visual Studio solution contains a project that uses LINQ to SQL classes (.dbml), the Windows installer project will fail to build.

Here is an example.
The following illustrates the solution, project, and file structure.
 Solution1.sln
  |- ClassLibrary1.csproj
      |- DataClasses.dbml
  |- Setup1.vdproj
      |- Primary output from ClassLibrary1

When building this solution, I always get the following message:
========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========

If I check the setup project output path, the setup.msi is generated there. And running the installer successfully deploys the classlibrary1.dll.

Here comes the surprising work around.
open the ClassLibrary1.csproj in the editor (Unload Project | Edit ClassLibrary1.csproj)
remove (or comment out) the following node
  <ItemGroup>
    <Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
  </ItemGroup>
reload project
restart the IDE
build solution
========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========

So what is this ItemGroup/Service/@Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}"?
Googling this GUID did not come up any useful info
However, the Windows registry editor helped to locate this under HKLM/SOFTWARE/Microsoft/VisualStudio/9.0/Services. It looks related to the O/R data class designer. This is very strange that it affects Visual Studio when building the setup (.vdproj).

Anyway, after removing (or commenting out) the node from the class library project (.csproj), I can build the whole solution again. And I have not seen any impact either on working with the LINQ to SQL data classes.

Tuesday, January 08, 2008

When using XML serialization on a class type that contains array like (array, collection, list, etc) properties, the de-serialization result could be inconsistent for an array type property comparing to a collection type property.

First of all, the following type “Foo” contains an int array private field and its encapsulating property:

    public class Foo

    {

        private int[] _bars;

        public int[] Bars

        {

            get

            {

                if (_bars == null)

                    _bars = new int[] { 0 };

                return _bars;

            }

            set { _bars = value; }

        }

    }

 

When doing a round trip of XML serialization of an instance of the “Foo” type:

        static void TFoo()

        {

            string xml = string.Empty;

            XmlSerializer xs = new XmlSerializer(typeof(Foo));

            using (StringWriter sw = new StringWriter())

            {

                Foo foo = new Foo();

                foo.Bars = new int[] { 1, 2, 3 };

                xs.Serialize(sw, foo);

                xml = sw.ToString();

                Console.WriteLine(sw.ToString());

            }

            using (StringReader sr = new StringReader(xml))

            {

                Foo foo = xs.Deserialize(sr) as Foo;

                foreach (int bar in foo.Bars)

                {

                    Console.WriteLine(bar);

                }

            }

        }

 

You get what you expect:

xml serialization good

Now let’s try with a “Foo2” type that contains a collection of int field and its encapsulating property:

    public class Foo2

    {

        private Collection<int> _bars;

        public Collection<int> Bars

        {

            get

            {

                if (_bars == null)

                {

                    _bars = new Collection<int>();

                    _bars.Add(0);

                }

                return _bars;

            }

            set { _bars = value; }

        }

    }

 

When doing a round trip of XML serialization of an instance of the “Foo2” type:

        static void TFoo2()

        {

            string xml = string.Empty;

            XmlSerializer xs = new XmlSerializer(typeof(Foo2));

            using (StringWriter sw = new StringWriter())

            {

                Foo2 foo = new Foo2();

                foo.Bars = new Collection<int>(new int[] { 1, 2, 3 });

                xs.Serialize(sw, foo);

                xml = sw.ToString();

                Console.WriteLine(sw.ToString());

            }

            using (StringReader sr = new StringReader(xml))

            {

                Foo2 foo = xs.Deserialize(sr) as Foo2;

                foreach (int bar in foo.Bars)

                {

                    Console.WriteLine(bar);

                }

            }

        }

You get what you do NOT expect:

xml serialization bad

In fact, disassembling the code from the xml serialization generated assembly shows that:

When the type of the property is collection, during de-serialization, an instance of the type “Foo” is constructed, followed by the “getter” of the collecton property is called, and finally all the elements in the xml are ADDed back to the collection property. Because it uses ADD, so any existing objects inside the collection property are kept untouched.

a_0_0.Add(System.Xml.XmlConvert.ToInt32(Reader.ReadElementString()));

In contrast, when the type of the property is array, the “indexer” is used to assign the element back to the array property.

a_0_0 = (global::System.Int32[])EnsureArrayIndex(a_0_0, ca_0_0, typeof(global::System.Int32));

a_0_0[ca_0_0++] = System.Xml.XmlConvert.ToInt32(Reader.ReadElementString());

 

 

In summary, instantiating a field inside its encapsulating property is commonly used, if the type is array like but not array (colleciton, enumerable, etc), you need to watch out for this xml serialization inconsistency.

Saturday, December 22, 2007

my iPod nano displayed "firewire connections are not supported. to transfer songs, connect the usb cable provided" message after I was wearing it and running in a raining condition, .
googled the error, and the closest usefule tip was to lay it under sunlight for a number of hours and wait for it to be dry.
i tried it and didn't work out for me.
then a friend suggested this ISO PRO Cleaner Pump Spray i tried it on the connection port, and it worked.