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 / IDE / November 2005

Tip: Looking for answers? Try searching our database.

EnvDTE.CodeElement.get_EndPoint throws Argument exception

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joginder Nahil - 05 Nov 2005 10:15 GMT
I have an Addin written VB which prints the source code in a .NET project.
The addin formats the source code using SmartFormat before printing the
source code.

Here is a code in the addin that formats the source code:

 dim ce as CodeElement
 dim td as textDocument
 dim pi as ProjectItem

 ' Determine project Item under the cursor
 td = applicationObject.ActiveDocument.Object
 ce = td.Selection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass)
 pi = ce.ProjectItem

 ' Format the project item
 td = DirectCast(pi.Document.Object, TextDocument)
 td.StartPoint.CreateEditPoint.SmartFormat(td.EndPoint.CreateEditPoint)

 For Each ce In ProjItem.FileCodeModel.CodeElements
    Debug.WriteLine( ce.EndPoint.Line )  ' ce.EndPoint.Line fails here
 Next

Line debug line in the For .. Next above fails with Argument exception:

'The parameter is incorrect' at ENVDTE.CodeElement.get_EndPoint()

The error only occurs if I set option 'Leave open braces on the same line a
constrcut' from the  Options -> Text Editor -> C# -> Formatting tab in the IDE

How can I avoid the error?

A test Addin that demonstrates the error can be downloaded using the
following link:

http://www.starprint2000.com/downloads/beta/getendpointtest.zip

Regards,
Joginder Nahil
www.starprint2000.com


If I check the option 'Leave open braces on the same line as construct' on
the C# Formatting options in the IDE then the an  
 
Carlos J. Quintero [VB MVP] - 07 Nov 2005 14:02 GMT
Does the problem happen removing the smart formatting, that is, with a C#
code already formatted? That is, can we remove the smart formatting from
your code to better diagnose the problem?

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

>I have an Addin written VB which prints the source code in a .NET project.
> The addin formats the source code using SmartFormat before printing the
[quoted text clipped - 41 lines]
> If I check the option 'Leave open braces on the same line as construct' on
> the C# Formatting options in the IDE then the an
Joginder Nahil - 08 Nov 2005 08:23 GMT
Hi Carlos,

Thanks for finding the time to respond. Nice to hear from you.

The released version of the addin VSNETcodePrint allows the user to format
the source code before printing it so that the connecting lines for the
language constructs are drawn correctly. (You can see the output samples on
my website www.starprint2000.com).

For this reason, the addin starts an Undo, format and prints the source code
and then aborts the Undo to ensure that the source code is left in its
origional state.

The error occurs if user sets option 'Leave open braces on the same line a
constrcut' from the Options -> Text Editor -> C# -> Formatting tab in the IDE
AND
The Undo context is started
AND
The source code is formatted

If you remove smart formatting then the problem does not occur. But I do
need to format the source code as I have stated in my opening paragraph above.

Regards,
Joginder Nahil
www.starprint2000.com

> Does the problem happen removing the smart formatting, that is, with a C#
> code already formatted? That is, can we remove the smart formatting from
[quoted text clipped - 45 lines]
> > If I check the option 'Leave open braces on the same line as construct' on
> > the C# Formatting options in the IDE then the an
Carlos J. Quintero [VB MVP] - 08 Nov 2005 12:02 GMT
Hi Joginder,

Yes, but we are trying to determine if the problem is:

1) The output of the format (whenever it happens, your add-in before
printing, or the user some days ago). I know that if you remove the
formatting process the problem disappears, but you are removing 2 variable
here: the process of formatting and the output of the formatting. You need
to remove only 1 variable of the problem. So, if the user (not your add-in)
formats the code with the option "'Leave open braces on the same line a
construct" and some time later your add-in prints (without reformatting),
does the problem happen? If yes, it would denote the the code model has a
bug retrieving edit points from code elements formatted in a certain way.
The solution would be some manual parsing or using the alternative method
CodeElement.GetEndPoint(part), playing with different parts, instead of
CodeElement.EndPoint.

2) The timing of the formatting process, which does not refresh the code
model after performing it. VS 2005 provides a new FileCodeModel2 with
methods Synchronize and a property ParseStatus.

But first you need to determine the exact problem. I hope that I explained
it well.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

> Hi Carlos,
>
[quoted text clipped - 26 lines]
> Joginder Nahil
> www.starprint2000.com
Joginder Nahil - 08 Nov 2005 12:43 GMT
Hi Carlos,

Good point. I can now conform that:

Please note that when I open the C# project, the source code in the
projectitem has { at the start of a line rather than at the end of each
statement.

If I format the source code in the IDE using Edit>Advanced>Format Selection,
the size of the ProjectItem ource code reduces from 590 lines to 560 lines
because { is placed at the end of each statement rather than at the beginning
of new line. When I run the Addin CodeElement.Endpoint does not raise an
exception.

If I format the same source code in the Addin using SmartFormat method then
CodeElement.Endpoint doesn not raise the exception

If I format the same source code in the Addin using SmartFormat method AND
the SmalFormat is performed after opening UNDO context then
CodeElement.Endpoint doesn raise the exception.

This suggests, as you suspected, code model has a bug retrieving edit points
when Foramt the source code after opening UNDO. I have now raised this as a
bug which is being investigated by Microsoft. I will let you know what they
say.

I appreciate you finding the time which I am sure you rather spend on
MZTools. BTW I am a registered user of your wonderful MZTools Addin and find
it very useful.

Thank you.



> Hi Joginder,
>
[quoted text clipped - 50 lines]
> > Joginder Nahil
> > www.starprint2000.com
Carlos J. Quintero [VB MVP] - 08 Nov 2005 14:16 GMT
Hi Joginder ,

I am glad that you are on the track to solve the problem. I find somewhat
strange that your add-in prints the source code with a different format than
the used by the user in the actual file, but if this is really needed and
the undo is causing problems, another approach is to close the file after
formatting without saving changes and open it again. This is what the
"Reload Active Document from Disk" feature of my add-in does, if you have
used it (I am glad that you like my add-in).

Be also aware that the smart formatting feature of VS.NET stops working "by
design" (for performance reasons) when the paragraph has 8,000 lines. You
may want to test it around that frontier, warn the user about it, or
document it in your help file.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

> Hi Carlos,
>
[quoted text clipped - 34 lines]
>
> Thank you.

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.