Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / October 2004

Tip: Looking for answers? Try searching our database.

Cannot retrieve the ProjectItemsEvents for Smart Device Project.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Trent - 14 Oct 2004 01:53 GMT
Does anyone have any idea how to attach to the eCSharpProjectItemsEvents in
C#?  These are the events that are associated with Smart Device Applications
created in C# and I need to track when files are being added/removed and
renamed, but you get a class cast exception if you try to cast it to
ProjectItemEvents.  Typically for ProjectItemEvents, I would do something
like this:
projectsEvents = (EnvDTE.ProjectItemsEvents)dte.Events.GetObject(
"CSharpProjectItemsEvents" );

which works.  However, if you change that call above to Smart Device
Application late-bound ProjectItemsEvents like this:
           projectsEvents =
(EnvDTE.ProjectItemsEvents)dte.Events.GetObject( "eCSharpProjectItemsEvents"
);

you get a class cast exception.  If you debug it, you see that the type that
is returned is "System.__ComObject" which indicates that it could not be
marshalled to a .NET managed type.  

Did the VisualStudio team forget to make the ProjectItemsEvents visible in
C# for Smart Device Applications?  If so, is there any other way to bind to
the events?  Any suggestions would be appreciated.

-Trent
Carlos J. Quintero [MVP] - 14 Oct 2004 14:46 GMT
Yes, there are problems with eXXXXProjectItemsEvents:

' KNOWN ISSUE: This causes "Catastrophic Error"
m_objeVBProjectItemsEvents =
DirectCast(m_objDTE.Events.GetObject("eVBProjectItemsEvents"),
ProjectItemsEvents)

' KNOWN ISSUE: This causes "Invalid cast"
m_objeCSharpProjectItemsEvents =
DirectCast(m_objDTE.Events.GetObject("eCSharpProjectItemsEvents"),
ProjectItemsEvents)

AFAIK, there is no workaround.

BTW, "System.__ComObject" means that the type is a COM wrapper. This is very
usual in VS extensibility. You can get the actual underlying type with
Microsoft.VisualBasic.Information.TypeName(obj).

There was a thread about this on the MS newsgroups or in the Yahoo forum but
after 5 minutes I have been unable to find it. Anyway I remember that the
conclusion was "no workarounds". MS has not commented on this issue.

Signature

Carlos J. Quintero (Visual Developer - .NET MVP)

The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com

> Does anyone have any idea how to attach to the eCSharpProjectItemsEvents in
> C#?  These are the events that are associated with Smart Device Applications
[quoted text clipped - 9 lines]
>             projectsEvents =
> (EnvDTE.ProjectItemsEvents)dte.Events.GetObject(
"eCSharpProjectItemsEvents"
> );
>
[quoted text clipped - 7 lines]
>
> -Trent
Trent - 14 Oct 2004 21:45 GMT
Carlos,
 Thanks for your response.  I took your suggestion to figure out the type
of the object being returned and I was able to determine the type as
ICSharpEventsRoot.  This was very useful.  I was then able to add a reference
to the esproj.dll that comes with Visual Studio in the VC#\VCPackages
directory which has those interfaces defined.  Then using the namespace
CSharp, I had access to the ICSharpEventsRoot interface witch in turn allows
you to access the project item events!  What a relief to get this out of the
way.  Here is what the code looks like:
               
projectsEvents =
(ProjectItemsEvents)(((ICSharpEventsRoot)dte.Events.GetObject(
"eCSharpProjectItemsEvents" )).get_CSharpProjectItemsEvents( null ));

I have tried it and verified that it works correctly.  I don't know if there
is a similar solution for VB Smart Application Projects or not, but it looks
like there may be.  Maybe a vb user should try a dll located the Vb7\Bin
directory.

This was definately a tricky one to figure out.

Thanks again,
Trent Barnes

> Yes, there are problems with eXXXXProjectItemsEvents:
>
[quoted text clipped - 47 lines]
> >
> > -Trent
Carlos J. Quintero [MVP] - 15 Oct 2004 10:49 GMT
Wow, you have solved 50% of this problem with Smart Device Projects!

BTW, for those of you who want to avoid the reference to esproj.dll, you can
use late binding (VB.NET code snippet):

       Private WithEvents m_eCSharpProjectItemsEvents As ProjectItemsEvents
       ....

       Dim objObject As Object
       Dim objCSharpProjectItemsEvents As Object
       Dim objType As Type

       objObject = m_objDTE.Events.GetObject("eCSharpProjectItemsEvents")

       objType = objObject.GetType()
       objCSharpProjectItemsEvents =
objType.InvokeMember("CSharpProjectItemsEvents", _
                 Reflection.BindingFlags.GetProperty, Nothing, objObject,
Nothing)

       m_eCSharpProjectItemsEvents =
DirectCast(objCSharpProjectItemsEvents, ProjectItemsEvents)

Now, the other 50% of the problem, eVBProjectItemsEvents, is more tough
because the exception is different. This line causes a "Catastrphic failure"
exception:

       objObject = m_objDTE.Events.GetObject("eVBProjectItemsEvents")

So, there is no much thing to do. Any ideas? The DLL for VB.NET is
msvbprj.dll, the namespace is VxExtensibility and the object is
IVxEventsRoot, but since that line causes that exception, we can not get
it...

Signature

Carlos J. Quintero (Visual Developer - .NET MVP)

The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com

> Carlos,
>   Thanks for your response.  I took your suggestion to figure out the type
[quoted text clipped - 19 lines]
> Thanks again,
> Trent Barnes

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.