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.