Exception has been thrown by the target of an invocation - InfoPath Dev
in

InfoPath Dev

Exception has been thrown by the target of an invocation

Last post 05-21-2007 07:09 AM by B.Shiva Prasad. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-21-2007 06:11 AM

    • edove
    • Top 500 Contributor
    • Joined on 08-21-2006
    • Posts 50

    Exception has been thrown by the target of an invocation

    Hi all, Ok.. I am using xdExtension:CalcDateDiff() in a rule to call some code in my infopath form.

    The code is as follows:

    public void CalcDateDiff()

    {

    XPathNavigator myNav = this.MainDataSource.CreateNavigator(); string dt1yr = myNav.SelectSingleNode("/my:myFields/my:orderDates/my:contractExit", this.NamespaceManager).Value.Substring(0, 4); string dt1mth = myNav.SelectSingleNode("/my:myFields/my:orderDates/my:contractExit", this.NamespaceManager).Value.Substring(5, 2); string dt1dy = myNav.SelectSingleNode("/my:myFields/my:orderDates/my:contractExit", this.NamespaceManager).Value.Substring(8, 2); string dt2yr = myNav.SelectSingleNode("/my:myFields/my:shipping/my:finalDateETD", this.NamespaceManager).Value.Substring(0, 4); string dt2mth = myNav.SelectSingleNode("/my:myFields/my:shipping/my:finalDateETD", this.NamespaceManager).Value.Substring(5, 2); string dt2dy = myNav.SelectSingleNode("/my:myFields/my:shipping/my:finalDateETD", this.NamespaceManager).Value.Substring(8, 2); DateTime firstDate = new DateTime(Convert.ToInt32(dt1yr), Convert.ToInt32(dt1mth), Convert.ToInt32(dt1dy)); DateTime secondDate = new DateTime(Convert.ToInt32(dt2yr), Convert.ToInt32(dt2mth), Convert.ToInt32(dt2dy)); TimeSpan diff = secondDate.Subtract(firstDate); //MessageBox.Show(Convert.ToString(diff.Days)); myNav.SelectSingleNode("/my:myFields/my:shipping/my:etdDiff", this.NamespaceManager).SetValue(Convert.ToString(diff.Days));

    }

    When I preview the form and activate the code I get this error message: "Exception has been thrown by the target of an invocation".. any ideas what that means??

  • 05-21-2007 06:20 AM In reply to

    • edove
    • Top 500 Contributor
    • Joined on 08-21-2006
    • Posts 50

    Re: Exception has been thrown by the target of an invocation

    By the way.. if I call this code from a button it works fine but I need the date diff to be updated every time one of the 2 dates is recalculated. Is there any other way to do this?
  • 05-21-2007 07:09 AM In reply to

    Re: Exception has been thrown by the target of an invocation

    Hi edove,

    By the way see this link, you will get some help

    http://www.geekpedia.com/Question70_Exception-has-been-thrown-by-the-target-of-an-invocation.html

    and for the second question, take the onAfterChange method for both date controls from there call the method "CalcDateDiff()" before that make a condition that if both date controls are not blank, so that the method calling time will reduce.

     

    Hope this will help you.

    B.Shiva Prasad
    InfoPath Dev,
    http://www.ggktech.com
    India
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.