David Foderick's Blog - OnMaterialize()

March 2005 - Posts

Always call DataBindings.Clear when disposing a form

Whenever you use control.DataBindings.Add to do data binding you need to take special care to clean up the databindings. The reason is that internally there is a reference to the bound control that is not released unless you do it in the Dispose. Therefore, in each base form in your control hierchy, put in some code to clean them up.

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

// This call is recommended by an MSDN article

Global.ClearBindings(this);

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );}

...

/// <summary>

/// According to article on MSDN, this will make bound object available for gc

/// </summary>

/// <param name="c"></param>

public static void ClearBindings(Control c)

{

Binding[] bindings = new Binding[c.DataBindings.Count];

c.DataBindings.CopyTo(bindings, 0);

c.DataBindings.Clear();

foreach (Binding binding in bindings)

{

TypeDescriptor.Refresh(binding.DataSource);

}

foreach (Control cc in c.Controls){

ClearBindings(cc);

}

}

 

This recommendation comes from an MSDN article along with many more excellent databinding recommendations.

Object-Relational mapping invades the Container

On the Java side of the fence, heavyweight containers (EJB, JBoss) are cozying up with Object-Relational Mapping vendors (JDO, Hibernate) to support OR Mapping inside the container. A wise move.

My good friend Robert Greene, VP of Product Strategy for Versant, has an article on how Entity Java Beans 3.0 compares to JDO 2.0. His basic premise is that with current technology (JDO 1.0 and 2.0) you can preview now what the new EJB 3.0 spec might look like in the future.

Now, I'm a .NET developer through and through but I have learned over the years that you can often see the future of .NET by looking at what is going on in the Java world now. Many of the best ideas on .NET came from the Java world and this continues to be the case. On the .NET side take a look at OR Mappers like Versant and NHibernate to see what the future of object persistence might look like.

Aspect Oriented Programming on .NET
Microsoft demoed the Phoenix Project at the Aspect Oriented Software Development Conference. Could this the future of IOC and DI at Microsoft? I hope so. Could also be that Versant could benefit from this technology when generating Persistent Capable code at compile time.
Closest thing yet to WinFS

As far as I can tell, this open source Base4.NET project is the closest thing yet to WinFS. I'll be taking some more time to study the internals and give a full report when I get a chance, but here is a taste.

The key insight here is that we can evolve to a post Object-Relational Mapping world. Currently, we create types for our object model separate from the storage mechanism. We then map the persistent fields of those types to tables in relational storage. What if we didn't have to do this mapping? What if our database understood our types? What if we had a rich object-oriented API right in the database? This is where we are headed.

Much more on this in a later post.

Another one for the blog roll
My friend Victor Campos has started blogging
GAC 2.0

Its interesting to see the changes that 64 bit machines will make on the Global Assembly Cache. On my 32 bit machine I have
c:\windows\assembly\GAC
c:\windows\assembly\GAC_32
c:\windows\assembly\GAC_MSIL

Obviously, GAC_32 holds 32 bit specific assemblies. GAC_MSIL holds processor independent assemblies (Intermediate Language is processor independent). What's in GAC? I'm not sure but it seems to be a lot of InterOp stuff.

Assemblies have an additional attribute called ProcessorArchitecture which apparently form part of the Strong Name. The ProcessorArchitecture can be x86, amd64, msil, or ia64.

On a related note, I was reading in Dr. Dobbs that AMD has an advantage right now (sorry, don't have a link right now) over Intel for 64 bit high end gaming machines. Guess I'll have to review my Intel-only policy and pick up a new AMD motherboard. Is that tax deductable?

Another DataSet lover bites the dust
One down. Upteen million to go.
Installing WinFS on XP

After a couple of missteps, here is my recipe for correctly installing WinFS on Windows XP.

Virtual PC
   1. Install Virtual PC
   2. Install XP in a new virtual machine
   3. Enable the performance booster under Action > Install or Update Virtual Machine Additions
      This part is very important! Without the performance booster the CPU for the VM will be pegged at 100% and it will take days to install the software.
   4. Install XP Service Pack 2

WinFS
   1. Install .NET SDK Partner Drop 6 (PD6)
   2. Install WinFS
   3. Install Visual Studio PD6. It cannot be installed from the CD. Instead the contents of the CD has to be copied to a local drive and the installation run from the local drive.

The Object-XML Impedence Mismatch

Joe Wood has several good posts covering the complications of using objects in a XML Messaging world.
OX Mapping - Mapping XML Schema to Classes Pt 1
OX Mapping - Mapping XML Schema to Classes Pt 2
OX Mapping - Pt 3 - .NET 3.0 and Indigo 2?

The bottom line is that XSD, the standard for defining types in XML, was created by a committee that threw in everything (including the kitchen sink) into the specification. As a result, XML Schema supports things like choice, sequence and restricting value space that do not map well to objects. That is why you will see WinFS support only a subset of XSD until these differences can be ironed out.

Recover images from .RESX files

When you add images to an ImageList it embeds them in Base64 format in the .resx resource file associated with your form. Sometimes you may loose the original image files. What's a resourceful programmer to do? Here a snippet of code that opens a .resx file, finds the ImageListStreamer that contains the images, reassociates the image stream back to the ImageList and then writes out each image bitmap to the root of the c: drive.

private void btnRead_Click(object sender, System.EventArgs e)

{

// Create a ResXResourceReader for the file items.resx.

ResXResourceReader rsxr = new ResXResourceReader(this.txtPath.Text);

// Create an IDictionaryEnumerator to iterate through the resources.

IDictionaryEnumerator id = rsxr.GetEnumerator();

// Iterate through the resources and display the contents to the console.

foreach (DictionaryEntry d in rsxr)

{

ImageListStreamer imgs = d.Value as ImageListStreamer;

if (imgs != null)

{

this.imageList1.ImageStream = imgs;

}

}

//Close the reader.

rsxr.Close();

// set the picturebox to the first image found

if (this.imageList1.ImageStream != null)

this.pictureBox1.Image = this.imageList1.Images[0];

// save all the images to disk

int j = 0;

foreach (Image i in this.imageList1.Images)

{

++j;

string fname = @"c:\Image"+j.ToString()+".bmp";

i.Save(fname);

}

}

Revenge of the Object Oriented Database

After spending several days at a WinFS conference and finding myself surrounded with OODBMS affecionados, I have a new appreciation for the OODB. Knowing their failure in the marketplace, I never imagined myself actually using one. But I'm coming around.

My new outlook is that Object Relational Mapping is simply an attempt to make the relational database look like an Object Oriented database. I will return to this subject at the end of the post but first lets look at the OODB.

There are two places where OODB shine.

1. Small database embedded in consumer devices. The FastObjects database inside a BMW car is a good example. The use cases are well defined. It will never be used as a general purpose business application. There is no DBA required. And what is the biggest market where such a database would be ideal? The consumer PC! WinFS anyone?

2. The other place where OODB shine is in certain classes of applications, usually outside the domain of general purpose business applications, that persist object graphs and rarely if ever need AdHoc reporting. CAD/CAM and modeling applications come to mind.

So where does this leave us? In today's business environment the relational database is a given. If you want to use an object model on top of a relational store then you have no choice. You simply must use some type of Object Relational mapping. But remember that adding another layer between your application and the database slows performance.

What if the performance hit is too great? What if the penalty of O/R Mapping outweighs the advantage of the relational engine. What if the extra work of maintaining mapping files is killing your agile development? What if the relational nature of your datastore is filtering up into your object model and constraining your application? What if your app doesn't take advantage of AdHoc reporting? What if you already have Object Oriented storage on your local PC in the form of WinFS and you just want to maintain lists and object models appropriate for individuals, not enterprises?

When WinFS is finally released years from now it will tilt the balance in favor of object-oriented development without the O/R mapper.

Net Knowledge Wiki

The Net Knowledge Wiki is up and running and, as always, will be a work in progress. My vision is that it will become a resource for anyone wishing to learn about ObjectOriented Programming, ObjectRelationalMapping, WinFS, Architecture, and Domain Model Business Objects. Providing basic definitions for concepts, code samples and media will give a gentle introduction to these sometimes difficult concepts.

I sincerely believe that most concepts can be described with a few sentences or a pictures and the hyperlink model makes it easier to see how all these concepts are related. The ramifications of each decision as you decide to implement specific technologies is the harder picture to see. Architecural guidelines will follow in longer White Paper articles.

Bill Gates: &quot;There is always an object model&quot;

Zachman knows it. Eric Evans knows it. And now I know the Chief Software Architect at Microsoft knows it.

Last Friday I had the good fortune to watch Bill Gates give a presentation about WinFS and I was struck by these words coming from the architect of the company that inflicted us with the DataSet and drag and drop two tier apps. 

There is always a domain model. A domain model is not a physical document or a specific architecture or a style of programming. You cannot point at a UML artifact and say this is the domain model. The domain model exists in the minds of the developers, business analysts and end users of the domain. Developers and architects may ignore it in which case it remains implicit. The fundamental insight is that it always exists. In the best environments the domain model is explicit and finds expression in a shared ubiquitous language and gets codified.

It is simply impossible right now for Microsoft to say publicly that you need to put the domain model at the front and center of your software development when they do not yet have the tools that make it possible. That will change.

Much will be written over the next few years about the coming changes at Microsoft. For me the most important one is that they understand that domain models and object models are important for the everyday business programmer. Once they have the tools ready then they can put out the message. The funny thing is that the tools already exist and the message is already being delivered by sources outside of Microsoft. You have only to put your ear to the ground and listen.

ObjectSpaces: A Raisin in the Sun?

Scott Bellware talks about the death of ObjectSpaces.

Is it a raisin in the sun? Will it explode?

Stay tuned...

A Platform for building Entity Business Objects
A rose by any other name would smell as sweet.