VS 2005 Beta 2 breaks VS.NET 2002 add-ins
After installing VS 2005 Beta 2 on a machine with VS.NET 2002 SP1
and VS.NET 2003, retrieving ProjectItemsEvents with
DTE.Events.GetObject("VBProjectItemsEvents") and assigning the
returning object to a ProjectItemsEvents variable declated
WithEvents causes exceptions on VS.NET 2002 add-ins. Those
exceptions do not happen in VS.NET 2003, and they did not happen
with VS.NET 2002 before installing VS 2005 Beta 2.
To reproduce the issue, create a VS.NET 2002 SP1 add-in with the
code below on a machine with VS 2005 Beta 2 and run it. The
exception thrown can be different if the add-in is being debugged or
it it is running alone (try both cases), but all exceptions seem to
be related to the fact that DTE.Events.GetObject returns an object
from the .NET Framework 2.0 (8.0.0.0), and this seem to happen
because VS 2005 Beta 2 overwrites the registry entry
HKEY_CLASSES_ROOT\CLSID\{DE6C1098-93CA-4F49-BEF0-262A13CA1176}
\InprocServer32 to put its version 8.0.0.0 replacing version
7.0.3300.0.
Kind regards,
Carlos Quintero (.NET MVP)
Private m_objDTE As EnvDTE.DTE
Private WithEvents m_objVBProjectItemsEvents As ProjectItemsEvents
Private WithEvents m_objCSharpProjectItemsEvents As ProjectItemsEvents
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
Try
m_objDTE = CType(application, EnvDTE.DTE)
m_objVBProjectItemsEvents = GetProjectItemsEvents("VBProjectItemsEvents")
m_objCSharpProjectItemsEvents = GetProjectItemsEvents
("CSharpProjectItemsEvents")
Catch objException As Exception
MessageBox.Show(objException.GetBaseException.ToString)
End Try
End Sub
Private Function GetProjectItemsEvents(ByVal sProjectItemsEvents
As String) As ProjectItemsEvents
Dim objObject As Object
Dim objProjectItemsEvents As ProjectItemsEvents
Try
objObject = m_objDTE.Events.GetObject(sProjectItemsEvents)
' The returned object type belongs to .NET Framework 2.0
' (8.0.0.0) despite the add-in is running under .NET Framework
' 1.0 (7.0.3300.0)
MessageBox.Show
(objObject.GetType.Assembly.GetName.ToString)
objProjectItemsEvents = DirectCast(objObject,
ProjectItemsEvents)
Catch objException As Exception
MessageBox.Show(objException.GetBaseException.ToString)
End Try
Return objProjectItemsEvents
End Function
Private Sub ProjectItemsEvents_ItemAdded(ByVal ProjectItem As
EnvDTE.ProjectItem) Handles _
m_objVBProjectItemsEvents.ItemAdded,
m_objCSharpProjectItemsEvents.ItemAdded
MessageBox.Show(ProjectItem.Name & " added")
End Sub

