ASP.NET Tasks

J

Jeff

I've created some code that takes some values off a database and
creates a customized Project 2003 Plan. When I run this code thru
using VS2005 it runs fine. However when I run the code outside of
VS2005 I get the following error.

Return argument has an invalid type.

Narrowing it down, this is the section of code that is throwing the
error.

foreach (msPrj.Task objTask in objProj.ActiveProject.Tasks)
{
if ((bool)objTask.Summary == false && (int)objTask.Duration != 0)
objTask.Duration = (int)objTask.Duration * ScalePercent;
}

In particular it's the objProg.ActiveProject.Tasks that is causing the
problem. I know this from trying to set a value of object to the task
collection and getting the same error.

Has anyone seen this? Have any ideas/solutions. The strange thing is
it works within VS2005.

Thanks
Jeff
 
J

Jeff

Ok, I made a little bit of progress. Hit another snag.

I can loop thru the tasks using the code below:

object oAP = objProj.ActiveProject;
Type typeAP = oAP.GetType();
object prjTasks = typeAP.InvokeMember("Tasks",

BindingFlags.DeclaredOnly |

BindingFlags.Public | BindingFlags.NonPublic |

BindingFlags.Instance | BindingFlags.InvokeMethod, null,oAP, null);

foreach (object prjTask in
((System.Collections.IEnumerable)prjTasks))
{
msPrj.Task myTask = (msPrj.Task)prjTask;
}

However when I try to cast the object to msPrj.Task
(Microsoft.Office.Interop.MSProject.Task) I get the following.

Unable to cast COM object of type 'System.__ComObject'

How do I cast the prjTask to be a Project task or is there a better way
to do this?

Thanks
Jeff
 

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