MZ-Tools Articles Series: BUG: ProjectItem.Collection returns a wrong collection for folders of SQL Projects of Visual Studio Team Edition for Database Professionals

 While adding support for SQL Server database projects of VS Team Edition for Database Professionals in my MZ-Tools add-in, I found a nasty bug in the implementation of the ProjectItem.Collection property when the item is a folder:

BUG: ProjectItem.Collection returns a wrong collection for folders of SQL Projects of Visual Studio Team Edition for Database Professionals
http://www.mztools.com/articles/2007/MZ2007031.aspx

I reported it to Microsoft through Microsoft Connect but they closed it without even acknowledging the bug:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=295434

I used Reflector for .NET to examine the internals of the package and I discovered the code that is wrong, so I opened a new one with a more detailed explanation:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=296758

Fortunately once you know the internals of the class that is wrong you can use Reflection to make the correct calls and get the expected result, so the next build of MZ-Tools will support database projects, but I hate when I spend time reporting a bug that will not be fixed or even acknowledged. BTW, they introduced a new bug in VS 2008 that did not exist in VS 2005:

EditPoint.FindPattern causes InvalidCastException on SQL editor of VSTS for DB Professional projects
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=295427

I wish they fix that one...

 

Published Wed, Sep 5 2007 7:29 by carlosq

Comments

# re: MZ-Tools Articles Series: BUG: ProjectItem.Collection returns a wrong collection for folders of SQL Projects of Visual Studio Team Edition for Database Professionals

Thank you, Carlos!

That would be really nice to see a new article on your great resource with some tips about how to work around the bug using reflection. Are you going to share it with us?

Wednesday, September 05, 2007 9:54 AM by Dmitry Pavlov

# re: MZ-Tools Articles Series: BUG: ProjectItem.Collection returns a wrong collection for folders of SQL Projects of Visual Studio Team Edition for Database Professionals

Yep. the workaround is:

If CType(objProjectItem, Object).GetType.Name.EndsWith("OAFolderItem") Then

  objParent = GetDatabaseProjectItemParent(objProjectItem)

Else

  objParent = objProjectItem.Collection.Parent()

End If

Function GetDatabaseProjectItemParent(ByVal objProjectItem As ProjectItem) As Object

  Dim objResult As Object = Nothing

  Dim objProjectItemObject As Object

  Dim objProjectItemType As Type

  Dim objPropertyInfo As System.Reflection.PropertyInfo

  Dim objNodeValue As Object

  Dim objNodeType As Type

  Dim objParentValue As Object

  Dim objParentType As Type

  Dim objMethodInfo As System.Reflection.MethodInfo

  objProjectItemObject = CType(objProjectItem, Object)

  objProjectItemType = objProjectItemObject.GetType.BaseType

  objPropertyInfo = objProjectItemType.GetProperty("Node", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)

  objNodeValue = objPropertyInfo.GetValue(objProjectItemObject, Nothing)

  objNodeType = objNodeValue.GetType

  objPropertyInfo = objNodeType.GetProperty("Parent")

  objParentValue = objPropertyInfo.GetValue(objNodeValue, Nothing)

  objParentType = objParentValue.GetType

  objMethodInfo = objParentType.GetMethod("GetAutomationObject")

  objResult = objMethodInfo.Invoke(objParentValue, Nothing)

  Return objResult

End Function

Thursday, September 06, 2007 4:00 AM by carlosq