October 2007 Blog Posts
AJAXToolkit and Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))

I was working on our Web 2.0 project today, and I kept getting one of the following errors with Visual Studio 2005 any time I tried to drag and drop an AJAX Toolkit control in my Web Site Project:

---------------------------

Microsoft Visual Studio

---------------------------

The operation could not be completed. Invalid FORMATETC structure

---------------------------

OK  

---------------------------

 

 

 

 

 

---------------------------

Microsoft Visual Studio

---------------------------

Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))

---------------------------

OK  

---------------------------

 

 

 

 

 

 

---------------------------

Microsoft Visual Studio

---------------------------

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

---------------------------

OK   Help  

---------------------------

So, after fighting this error for hours and hours, trying to get my AJAXToolkit Drag & Drop working, the problem turned out to be a solution wide reference problem.

I removed all project references from the solution (actually remove them from the solution by Right Clicking the Project in Solution Explorer > Remove), then added them back one by one.  Recompiled, and the problem seemed to go away.

UPDATE 1/23/2008: Please check my other post on this problem.

Microsoft, thanks for another the great and descriptive error message... *sigh*.mad0223.gif     mad0228.gif

How to create tile-perfect diagonal lines in Illustrator

Creating diagonal lines in Adobe Illustrator is somewhat of a pain.  I'm creating the graphics for our new Web 2.0 site, and had a hard time creating diagonal lines.  But here I'll show you how to create angled 45deg Web 2.0 lines in Illustrator with relative ease.

 

First, turn snap to grid on.

 image

Select the line tool, set the stroke width to 5pt (or your desired width).

image

Make sure your stroke color is the color you want it.  In this example, my stroke color is black.  Next, on the canvas, draw a diagonal line that is slightly larger than the major grid box.

image

image

Next, Move-Copy the line 12px away from the first line.

image

image

Hit the copy button.  Once your copy appears on the canvas, press CTRL-D to repeat.  You need to repeat until you have a major grid completely covered.  Like so:

image

Next, select all the diagonals then go to Object>Path>Outline Stroke as shown below:

image

image

image

Next, draw a square (with no fill and no stroke) as the same size of a major grid box (72px by 72px) and place it over the covered major grid like this:

image

Your square should be 72px width and height.  Next, select all, and click Divide on your Path Finder as shown below:

image

image

image

Ungroup and cut the excess diagonals from the major square:

image

image

image

Now you should have a nice cut pattern like the one above.  Select your pattern and drag it to your swatches.  Once you see your pattern in your swatches palette you can then use the swatch and apply a fill to your irregular pattern and archive the following results:

image

Pretty cool! :)  Hope that helps! happy0122.gif

Helpful Tip:

If you want to apply a radial gradient or a fill color to your stripes, you'll notice that this method wont work.  But to make it work, you just need to continue a little more.  Select the original pattern you created:

image

Next, Merge:

image

(This effectively merges the original invisible (no stroke no fill) square with your diagonals.)

If you choose to stop here, you'll notice the pattern diagonals still act like individual objects when a fill is applied, and you get something like a diamond shape when applying a radial gradient:

image

To unify the stripes as a single object do the following (and ultimately, have the gradient applied to the diagonals as a whole, instead of individually), Ungroup:

image

Then Add Shape Area in your path finder tools:

image

Then click Expand:

image

Now you have the gradient applied to the whole shape instead of each individual diagonal line:

image

There we go!  Hope that helps!

NHibernate and Inverse=True|False Attribute

In order to truly understand the inverse attribute in NHibernate, you need to first look at your relationship from the database table point of view and how your domain objects maps into their respective tables.  It comes down to determining who is the owner of the relationship association between the parent and child objects.

Suppose you have ParentTable (parentId PK, parentcol1, parentcol2) and ChildTable(childid PK, parentid FK, childcol1, childcol2).  In a one-to-many relationship, you will have one parent and many children.  The ChildTable has a primary key and foreign key.   The foreign key is a reference to the primary key in the ParentTable.  If you look at the ChildTable, you will notice that the ChildTable stores extra information about a row in the ParentTable via the ChildTable's parentId foreign key.  Using this perspective, the "child" owns (knows about) the relationship it has with its parent row.  So, the child will be the owner of the relationship in this one-to-many relationship.

Where does inverse come in?  Well, from the Parent's perspective, since the parent doesn't own the relationship it is considered the "inverse" of the relationship.  Below is some additional information I pulled down an edited from IBM's websphere pages:

http://www.ibm.com/developerworks/websphere/techjournal/0708_vines/0708_vines.html

Many-to-one relationship

The entity declaring the many-to-one relationship is the child object (or owner of the relationship), as its table has the foreign key, while the object that is referenced by the entity declaring the many-to-one relationship is the parent object. Since its table doesn't have the foreign key, it is the non-owner, or inverse of the relationship.

Hibernate conventions

In Hibernate, many-to-one relationship maps as follows:

  • Use many-to-one element in the child class.
  • Define the primary key in the parent class.

 

One-to-many relationship

A one-to-many relationship defines a reference to a collection of objects. It is the most common kind of relationship that you will find in object models due to the fact that use cases typically require traversal from the parent object to its children, but may or may not require traversal from the child back to its parent; which means a unidirectional one-to-many relationship will suffice in most cases.

The entity declaring the one-to-many relationship is the parent object (and is the non-owner). The table for this entity defines the primary key, but it does not have the foreign key -- that is in the child.

In Hibernate, the mapping of one-to-many relationships is generally done by adding a column to the child table for the foreign key, but the details of the mapping differs depending on whether it is a unidirectional or a bidirectional one-to-many relationship.

In the unidirectional case, the foreign key column in the child table doesn't map to a property in the child object; it is in the data model, but not the object model. Since it is unidirectional there is just a property in the parent object [that contains a collection of children]; not the child [the child object does not contain any information back to the parent]. In addition, the foreign key column [in the child table] has to be defined as nullable because Hibernate will first insert the child row (with a NULL foreign key) and then update it [the inserted row] later [with the parent's primary key].

In the bidirectional case, the object-relational mapping is better because there is a property in the child object for the foreign key column, and that column doesn't have to be nullable in the database. But the resulting object model has cyclic dependencies and tighter coupling between the objects, and requires additional programming to set both sides of the relationship.

As you can see, there are several tradeoffs to consider with regard to the definition of one-to-many relationships, but using unidirectional relationships is generally recommended unless there are use cases that indicate the need for navigation in both directions.

Hibernate conventions

In Hibernate, one-to-many (unidirectional) relationships map as follows:

  • Use the set, bag, or list with one-to-many sub-element in parent class.
  • Create a foreign key in the table representing the child class if the relationship is unidirectional; otherwise, use the many-to-one relationship for a bidirectional relationship.

There are some additional features that are often used in the definition of one-to-many relationships[...]:

  • Hibernate

    • inverse="true"
      In Hibernate, you might encounter the inverse="true" attribute being used in the definition of a bidirectional relationship. If so, don't worry, because this feature is equivalent to ... the non-owner of the relationship whose table doesn't have the foreign key. Similarly, the Hibernate inverse="false" attribute is equivalent to the ... owner of the relationship whose table has the foreign key.

      In general, these notions align, except for the case where someone defines a Hibernate mapping with inverse="true" set on the many-to-one side of a bidirectional relationship. If you find such a mapping, you should change it ..., as it is not a best practice in Hibernate and does not generate optimal SQL. For instance, if the many-to-one side is set to inverse="true" then every time you create a child, Hibernate will execute two SQL statements, one to create the child and one to update the child with the foreign key of the parent. Changing it to inverse="false" on the many-to-one side and setting inverse="true" on the one-to-many side will fix that oversight ...

 

Many-to-many relationship

A many-to-many relationship defines a reference to a collection of objects through a mapping table. Many-to-many relationships are not all that common in an object model, but they will generally be bidirectional.

Like the other bidirectional relationships, there is an owning and a non-owning side. In this case, the owning side has the mapping table, instead of the foreign key. Either side can be designated as the owning side; it doesn't matter which side you pick.

Hibernate conventions

In Hibernate, many-to-many relationship maps as follows:

  • The non-owner uses the collections (set, bag, or list) element with the inverse="true" attribute, the table attribute, the key sub-element, and the many-to-many sub-element.
  • The owner of the relationship uses the collections (set, bag, or list) element with the table attribute, the key sub-element, and the many-to-many sub-element.
20 Comments Filed Under [ NHibernate ]
Svn Post-Commit Troubleshooting

We use Subversion (cygwin svnservice flavor).  I recently updated our source code repository server here at Bit Armory.  One thing is for sure, Cygwin updates never work like Microsoft updates.  Anytime I've updated Cygwin, it has always broken something.  For instance, today, my recent Cygwin update broke the Svn post-commit script that sends out an email to the developers on a source code check-in.  So, what was the problem?

Cygwin updates scripts tend to break things by reapplying (resetting) permissions on the binary directories (/bin, /usr/sbin ...etc...).  When permissions are reapplied, accounts such as the SYSTEM service account loose execution rights.  So, if your svnservice is being run by cygrunsrv under a SYSTEM service account (yes, I know, it shouldn't be running under SYSTEM), you'll run into a lot of errors if you try to execute cygwin applications from the SYSTEM account.  So, as it turns out, the lack of the execution "chmod ugo+x" on svnlook.exe and other supported files caused the post-commit script to fail.

Here are some important tips / tricks that I use to help keep cygwin setup tame.

Set Execute Permissions

Make sure all programs / scripts you intend to run (and any child processes / scripts that are run as a consequence) have execute permissions.  For example in my case:

  • svnlook.exe
  • sendmail.exe
  • ssmtp.exe
  • perl.exe
  • post-commit

Simulate svnserve launching post-commit

Simulate svnserve executing your post-commit script file by using:

  • $env - /bin/sh /path-to-svn-repo/Project/hooks/post-commit /path-to-svn-repo/Project X

where X is a revision number.  "env -" launches a process with an empty environment just like svnserve does.  This means you need to setup %path% environment variables for your script to run. You can take this one step further and load this as a system service by using:

  • cygrunsrv --install svntest --path /bin/env.exe --args "- /bin/sh /path-to-svn-repo/Project/hooks/post-commit /path-to-svn-repo/Project X"
  • net start svntest

and then check /var/log/svntest.log for any critical errors.  Can't get any more simulated than that.

Use strace

Use strace to trace svnserve by executing:

  • strace.exe svnserve.exe args > output.txt

And you'll get some decent output on how svnserve.exe is running.  Search for post-commit in output.txt, errors, and failures.

Use Filemon

You can also use Filemon/ProcessMonitor from www.sysinternals.com and watch the svnserve.exe process on a windows machine for any weird errors and anything that looks suspicious.

Hope that helps.  Happy coding! smile.gif