Skip to main content
The World's Best Known Brand for Microsoft Project and Project Server Expertise

Project Server Experts Community Site

Search
Project Server Experts Community Site
Project Server Help Blog
MSProject Experts
Training Schedule
Contact Us
  
Project Server Experts Community Site > Project Server FAQ KnowledgeBase > SolveCOMExceptionError  


How to solve the COMException error when using TimeScaleData function and .NET



Microsoft Project Server Frequently Asked Questions (FAQs): Overview



Microsoft Project Server Frequently Asked Questions (FAQs): Details

Background Information

Using the TimeScaleData function in a C# or VB.NET loop (when iterating through a list), may result in a COMException error. This error is caused by an internal resource limit in Microsoft Project, and because the .NET garbage collector does not clear up the references fast enough.

Resolution

The solution is to call the System.GC.Collect() at the end of the loop. The following is an example that iterates through the assignments of a resource (and does nothing....)

Private Sub transferResData(ByRef res As MSProject.Resource, ByVal startDate As Date, _

        ByVal endDate As Date)

    Dim assign As MSProject.Assignment

    Dim tsv As MSProject.TimeScaleValues

    Dim value As MSProject.TimeScaleValue

 

    Try

        If res.Assignments.Count > 0 Then

            For Each assign In res.Assignments

                If assign.TaskUniqueID > 0 Then

                    tsv = assign.TimeScaleData(startDate, endDate, _

                        MSProject.PjAssignmentTimescaledData.pjAssignmentTimescaledWork, _

                        MSProject.PjTimescaleUnit.pjTimescaleMonths, 1)

                    For Each value In tsv

                        Try

                            ' Do something with the value

                        Catch ex As Exception

                            MsgBox(ex.Message)

                        End Try

                        System.GC.Collect()

                    Next value

                End If

            Next assign

        End If

    Catch ex As Exception

        MsgBox(ex.Message)

    End Try

End Sub

Contributed by Project Server Expert, Hugues Perron

With thanks to Brook Miles for the solution

 

 

Stay Connected

Join Our
LinkedIn Network
Follow Us
on Twitter

About FAQs

Microsoft Project Server Frequently Asked Questions (FAQs) provide information about Microsoft Project Server 2002, Microsoft Project Server 2003, Microsoft Project Server 2007, and Microsoft Project Server 2010.

Topics include common errors and the Project Server queue, project manager and resource manager approvals, enterprise calendars, enterprise custom fields, enterprise projects and the enterprise resource pool, user access, reports and OLAP analysis, resource work, project costing, task progress reporting and timesheets, Project Web Access (PWA) and Project Professional, check-out check-in and the local cache, saving and publishing, and issues risks deliverables documents and project workspaces.

About This Site

Project Server Experts (www.projectserverexperts.com) is an online community that provides answers to Project Server Frequently Asked Questions, allows members of the Project Server community to connect with one another by uploading their Business Cards, provides links to online Project Server resources, and links to Microsoft Project and Project Server related jobs.

This site is brought to you by MSProjectExperts. If you find the information posted here useful, please consider visiting our commercial site (www.msprojectexperts.com) for Project Server books, Project Server training and Project Server consulting services. Please support our sponsors. Thanks. -- The MSProjectExperts Team

Submissions

We welcome content submissions. We give author credit and cross link on all accepted articles. Please send your articles and suggestions to info(at)msprojectexperts.com.

Copyright

Reproduction of content on this site is strictly prohibited without the express permission of MSProjectExperts. Copyright (c) 2011 CHEFETZ LLC. All rights reserved