Showing results 1 to 8 of 8

Thread: Access Violation when iterating archive variables

  1. #1
    Join Date
    10.12.2010
    Posts
    55

    Default Access Violation when iterating archive variables

    Im listing the variables in our archive with the function:
    private void BindArchiveVariables(TreeNode projNode, IProject iProject)
            {
                var variables = iProject.Archives().Item(0).ArchiveVariables();
                var cnt = variables.Count;
                for (int i = 0; i < cnt; i++)
                {
                    try
                    {
                        var arcvariable = variables.Item(i);
                        if (arcvariable == null)
                            continue;
                        
                        var varname = arcvariable.Name;  // <-- Can throw an exception
                        var child = new TreeNode(iProject.String(varname));
                        projNode.Nodes.Add(child);
                    }
                    catch (Exception ex)
                    {
                        string s = ex.Message;
                    }
                }
            }

    Two variables (index 940 and 945) in my archive throws an ACCESS_VIOLATION exception at the line:

    var varname = arcvariable.Name
    The exception is caught and the VSTA form continues to work, but as soon as I closes the form, but the entire runtime crashes.

    Is there any way to catch the exception without crashing the runtime, or is it the archive that is corrupt? How should I handle this?
    Last edited by brc : 25th April 2012 at 10:49

  2. #2
    Join Date
    10.12.2010
    Posts
    55

    Default Re: Access Violation when iterating archive variables

    I have just tried to delete all archive files from the project. It is still the same two variables throwing the same exception, so it does not seem to be a corrupt archive


    !!! Update !!!

    I looked into the archive, and the two problem variables have been deleted, so that they are displayed as "" in zenon editor.

    How do I detect that in C# so I can skip the variables?
    Last edited by brc : 25th April 2012 at 11:23

  3. #3
    martins Gast

    Default Re: Access Violation when iterating archive variables

    hi,

    the exception is handled by the catch-block, but when closing the Form, the runtime crashes? Is it an unhandled exception that makes the runtime crash?

    I will look at this as soon as I find some time.

    best regards,
    Martin

  4. #4
    Join Date
    10.12.2010
    Posts
    55

    Default Re: Access Violation when iterating archive variables

    > the exception is handled by the catch-block, but when closing the Form, the runtime crashes?

    yes

    > Is it an unhandled exception that makes the runtime crash?
    I havnt been able to find any other exceptions. I will try to wrap the entire thing with a try/catch and get back to you if I finds anything.

  5. #5
    martins Gast

    Default Re: Access Violation when iterating archive variables

    hi,

    could you try to debug it and post the information of the Immediate Window here when it crashes? The Immediate Window should tell you some more information like "First chance exception occured at ..." and similar lines to this.

    Maybe we can find out something more with this. I will have a look at your issue some time this week.

  6. #6
    martins Gast

    Default Re: Access Violation when iterating archive variables

    hi,

    I just tested it myself and I cannot reproduce it - or I made something different than you.

    This is the way how I tried it myself:

    • Created five variables
    • Created new archive with those five variables
    • Set some settings for archiving (don't think this is so important)
    • Create a VSTA function (see below)
    • Start runtime and execute the VSTA method
    • Close runtime, delete one variable, restart runtime
    • Execute VSTA method again


    In the first run, my entries in the Immediate Window looks like this:

    Var1
    Var2
    Var3
    Var4
    Var5

    In the second one, it looks like this:

    Var1
    Var2
    Var4
    Var5

    so I don't get any exceptions here... I tested this with version 7, maybe you can tell me which version you are using, so I can test it there as well.

    So this is my code - basically it's just like yours, I adapted it a little bit.

    public void Macro_TestArchive()
            {
                var variables = this.Archives().Item(0).ArchiveVariables();
                var cnt = variables.Count;
                for (int i = 0; i < cnt; i++)
                {
                    try
                    {
                        var arcvariable = variables.Item(i);
                        if (arcvariable == null)
                            continue;
    
                        var varname = arcvariable.Name;  
    
                        System.Diagnostics.Debug.Print(varname);
    
                    }
                    catch (Exception ex)
                    {
                        string s = ex.Message;
                    }
                }
            }

    I will let you know when I find out more information about that.

    Best regards,
    Martin

  7. #7
    Join Date
    10.12.2010
    Posts
    55

    Default Re: Access Violation when iterating archive variables

    Oh, sorry. Forgot the version.

    I'm using 6.51 SP0.

    Does your first exception get thrown?

    Thank you for your help

  8. #8
    martins Gast

    Default Re: Access Violation when iterating archive variables

    hi,

    you are right - I was able to reproduce this with 6.51 and there is an error in the zenon API. I found an entry in our defect database to this, this will be fixed in the next Build (which will be Build 13) for 6.51 SP0.

    However, you could maybe use Build 11 or Build 12 because the behaviour of the unhandled exception was fixed there - BUT unfortunately, there is a side-effect which maybe renders the usage of ArchiveVariables useless to you: ArchiveVariables.Item(0) contains the trigger variable instead of the first variable in the archive. We are already aware of this - this will be fixed in Build 13.

    Again, the changed behaviour is only part in these two builds - Build 13 will revert this, it will behave as in prior versions and there will be no more unhandled exceptions.

    Until then, I can't really offer you another solution to this. I would suggest that you get in contact with your local COPA-DATA representative so he contacts you when Build 13 will be released.

    Hope I could help,

    best regards,
    Martin

Similar Threads

  1. Database Access
    By whitetaru in forum Drivers
    Replies: 11
    Last Post: 20th September 2011, 22:48
  2. Program access to structure datatype variables
    By stolyarov_as in forum VBA
    Replies: 2
    Last Post: 8th August 2011, 14:21
  3. Symnbol Access by VBA
    By acko01 in forum VBA
    Replies: 1
    Last Post: 29th March 2011, 02:14
  4. Access to operating system
    By michael_k in forum Engineering Studio & Service Engine (former zenon Editor & Runtime)
    Replies: 4
    Last Post: 13th January 2010, 05:22
  5. PLC Variables and Internal Variables
    By madphilly in forum Drivers
    Replies: 1
    Last Post: 4th June 2008, 06:59

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •