Error in _Startup() - InfoPath Dev
in

InfoPath Dev

Error in _Startup()

Last post 05-23-2008 11:16 PM by Cutejon. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 04-03-2008 12:20 PM

    Error in _Startup()

    I added code to the _Startup method to  aid in form validation on submit. Basically we want to see if a field has been changed since the form was loaded. If so we preform custom validation based on the original/new value.

     

    Here is my startup code:

    public void _Startup(Application app, XDocument doc)

    {

    this.thisXDocument = doc;

    this.thisApplication = app;

    openingJobNumber = this.thisXDocument.DOM.selectSingleNode("/my:job/my:number").text;

    }

    Here is the error:

     System.InvalidOperationException
    The _Startup or _Shutdown method in this form's code contains one or more calls to members of the Microsoft.Office.Interop.InfoPath.SemiTrust namespace. Calls to this namespace from these methods are not permitted.
       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
       at Microsoft.Office.Interop.InfoPath.SemiTrust.InfoPathOMHelper.Run(String assemblyFullPathName)

  • 04-03-2008 12:39 PM In reply to

    I believe you would want to put your code in Onload event. that is the typical place.

    On Startup there has not been a form loaded yet and that is why you can not make references.

     

    How are you assigning JobNumber?  Does it come from a database? does it need to be unique?

  • 04-03-2008 01:36 PM In reply to

    Clay,

    Thanks for the reply. For some reason, when I place this code in the OnLoad event, it doesn't run, that's why it's in the _Startup to begin with. JobNumber is a text field entered, but it is also the filename.Yes, it does need to be unique and part of the validation is to eliminate duplicate job numbers in forms started by two different users. I.E. Person A starts Job 123 and before he saves, person B starts Job 123. The form currently allows for the last saved job to overwrite.

  • 04-03-2008 01:48 PM In reply to

    WOW. That's weird. Thanks to Clay's post I revisited the OnLoad method, deleted it, and re-wrote the code. This fixed the issue.

    Thanks AGAIN Clay! 

    Looks like the method signature was incorrect:

     It changed from:

    [InfoPathEventHandler(EventType = InfoPathEventType.OnLoad)]public void OnLoad(DocReturnEvent e)

    {

    ...

    }

    To:

    [InfoPathEventHandler(EventType = InfoPathEventType.OnLoad)]public void FormEvents_OnLoad(DocReturnEvent e)

    {

    ...

    } 

     

  • 04-03-2008 01:58 PM In reply to

    Do you need a method for auto asigning numbers? Which are unique and sequential.  Having the user create one or pull from a common list is usually problematic.

    I could show you a couple different possibilities. Email me if you are interested.

  • 05-23-2008 11:16 PM In reply to

    • Cutejon
    • Not Ranked
      Male
    • Joined on 03-26-2008
    • Philippines
    • Posts 20

    Hi Clay,

    My original problem was to know how to use DavAdapter in Infopath 2007 via VB script coding. My research then showed me, to use this class, I have to include _startup to get the variable for xdocument. Unfortunately testing it was without success. Can you please help me know where to declare this ?  Or know what steps to take to make xdocument available in my code, and in turn use DavAdapter.

     Your help will be greatly appreciated.

    links: http://www.infopathdev.com/forums/p/7891/28808.aspx#28808 


    thanks
     

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.