Timescale Data via C#


G

gvolp

I am writing a VSTO add in using C# in Visual Studio 2008 (with Beta SP1
installed). I am using Project Pro 2007 with SP1. Operating system XP Pro
with the latest service packs.

When I iterate over the timescaled values collection returned from
TimeScaleData (see code snippet below) about the tenth time into the
iteration the ts.Value throws an exception (“An unexpected error has occurred
with the method†the get_Value method.).

I have seen on several newsgroup threads that this is an issue with the
TimeScaleValues collection releasing resources prematurely. The same
iterative technique/code works fine from VBA.

How can I mark the TimeScaleValues object as “don’t release†or whatever I
need to do to make this work?

foreach (Microsoft.Office.Interop.MSProject.Resource rsc in
AppCfg.curPrj.Resources) {

foreach (Microsoft.Office.Interop.MSProject.Assignment assign in
rsc.Assignments) {


Microsoft.Office.Interop.MSProject.TimeScaleValues tsv =
assign.TimeScaleData(assign.Start, assign.Finish,
PjAssignmentTimescaledData.pjAssignmentTimescaledWork,
PjTimescaleUnit.pjTimescaleDays, 1);


foreach (Microsoft.Office.Interop.MSProject.TimeScaleValue ts in tsv) {
object obj = ts.Value
}

}

}
 
Ad

Advertisements

J

Jack Dahlgren

A few things to try:

Use Try / Catch to recover from the error or display some further
information to troubleshoot with. If the problem is that it is just running
out of values then resuming the next tsv would be a reasonable solution. It
is hard to know without seeing your project data and the values that are
returned.

Try using VB instead of C#. It may be a bug in the C# implementation. VB is
also a bit easier to code when you are porting over VBA. Optional parameters
can be omitted, most VBA code can come over with very minor changes.

Those are the points where I'd start troubleshooting.

-Jack Dahlgren
 
Ad

Advertisements

G

gvolp

Jack,

Thanks for your reply. In my original code (i posted a short snippet) I have
exception handling included. What occurs is the dreaded "unexpected error has
occurred
with the method". If I catch the exceptions, it just keeps throwing them
till the end of the iteration has been reached. I know there is data beyond
the current timescale value (the vba code produces it just fine). I am aware
of the "" returned and handle them fine. I have tried multiple projects with
more than 10 values (in this case pjTimescaleDays) and they all throw this
error so it is not project specific. If your up for it and have VS2007
installed, I could send you an mpp file and a simple test project I created
to reproduce the error.

I tried using VB.Net and it gave me the same error. This leads me to believe
its in the combination of Projects COM implementation and/or the .Net 3.5
framework implementation?

I'm perplexed. Thanks for answering.

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top