C# Static string appending problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BA

    C# Static string appending problem.

    Hello,

    I have a very strange code behavior that I cannot make heads or tails of:

    I have c# code being executed in BizTalk assemblies which is acting very
    strangely.

    In my BizTalk process I call a static method:

    public static string ValidateMessage (params...)

    When I call this method the FIRST TIME, everything is fine, and the
    DebugView outputs the following...

    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ASSERTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique




    Then it gets strange.... when I execute it a second time, I get:

    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ASSERTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique


    A third time I get:

    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ASSERTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping thru
    lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique


    And so on... It keeps piggy-backing these past method calls and I don't know
    why!

    If I restart the BizTalk host, the first call behaves normally as described
    above and then this problem begins again.

    Someone suggested there was something static is being appended, but I cant
    see it in the code. If you see something, please let me know. The reason I
    tend to agree is because the line "AL.TechSvcs.Pr ocurement.Suppo rt ::
    BusinessRulesVe rification ASSERTED " appears 2/3 of the way thru and its the
    very first thing which is done when the code is executed. It does not
    appear that the logic is executing 3x, just the output to the debug view.

    If there is something appended, where am I allowing this to happen in the
    code below?

    using System;
    using System.Xml;
    using System.Collecti ons.Generic;
    using System.Text;
    using System.Collecti ons;
    using System.Diagnost ics;
    using Microsoft.RuleE ngine;

    namespace AL.TechSvcs.Pro curement.Suppor t
    {

    public class BusinessRulesVe rification
    {
    public BusinessRulesVe rification()
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification ASSERTED");
    }


    public static string VerifyPOLineUni que(TypedXmlDoc ument rootNode,
    string PoNum, string xpath, string xLineNum)
    {
    XmlNodeList PoLines;

    try
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: VerifyPOLineUni que STARTED");
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: PO NUM = " + PoNum);

    PoLines = rootNode.Docume nt.SelectNodes( String.Format(x path,
    PoNum));

    if (PoLines.Count 0)
    {

    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: PO lines 0");

    //PUT MATCHING PO NUMBERS IN AN ARRAY
    ArrayList arrLineNums = new ArrayList();
    foreach (XmlNode node in PoLines)
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: looping thru lines");

    arrLineNums.Add (node.SelectSin gleNode(xLineNu m).InnerText);
    }

    int i, j;

    for (i = 0; i < arrLineNums.Cou nt - 1; i++)
    {
    for (j = i + 1; j < arrLineNums.Cou nt; j++)
    {
    if (arrLineNums[i].Equals(arrLine Nums[j]))
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort
    :: BusinessRulesVe rification :: found non-unique line !!");

    return "False";
    }
    }
    }
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: all lines are unique");

    return "True";
    }
    else
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: no PO lines found");
    return string.Empty;
    }
    }

    catch (Exception e)
    {
    Debug.WriteLine (exception.ToSt ring());
    EventLog.WriteE ntry("Biztalk", String.Format(" Error occured
    when trying to find unique PO lines. Return empty string"),
    EventLogEntryTy pe.Error);
    throw e;
    }

    }
    }
    }


    If anyone has seen this or knows what I am doing wrong, please help.

    Thanks,

    BA


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: C# Static string appending problem.

    BA,

    It doesn't look like you are doing anything (like storing a static
    variable) which would cause this to happen. Because of that, I would have
    to assume that your xpath expression that is being passed to the method is
    producing duplicate lines, or your XML document has the extra lines the
    second time around.

    In other words, it's not the code, it's the input.

    One thing I did notice, in your try/catch block, you have the line
    "throw e". You should change that to just "throw" so that the original
    stack trace information is retained, unless you ^want^ the stack trace
    information to start from the place where you re-throw the exception.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "BA" <biztalk.archit ect@gmail.comwr ote in message
    news:%23AH9SM%2 3bHHA.4872@TK2M SFTNGP03.phx.gb l...
    Hello,
    >
    I have a very strange code behavior that I cannot make heads or tails of:
    >
    I have c# code being executed in BizTalk assemblies which is acting very
    strangely.
    >
    In my BizTalk process I call a static method:
    >
    public static string ValidateMessage (params...)
    >
    When I call this method the FIRST TIME, everything is fine, and the
    DebugView outputs the following...
    >
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ASSERTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines >
    0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    >
    >
    >
    >
    Then it gets strange.... when I execute it a second time, I get:
    >
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines >
    0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ASSERTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines >
    0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    >
    >
    A third time I get:
    >
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines >
    0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines >
    0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ASSERTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification ::
    VerifyPOLineUni que STARTED
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO NUM =
    V36000630000100 0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: PO lines >
    0
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: looping
    thru lines
    AL.TechSvcs.Pro curement.Suppor t :: BusinessRulesVe rification :: all lines
    are unique
    >
    >
    And so on... It keeps piggy-backing these past method calls and I don't
    know
    why!
    >
    If I restart the BizTalk host, the first call behaves normally as
    described above and then this problem begins again.
    >
    Someone suggested there was something static is being appended, but I cant
    see it in the code. If you see something, please let me know. The reason
    I
    tend to agree is because the line "AL.TechSvcs.Pr ocurement.Suppo rt ::
    BusinessRulesVe rification ASSERTED " appears 2/3 of the way thru and its
    the
    very first thing which is done when the code is executed. It does not
    appear that the logic is executing 3x, just the output to the debug view.
    >
    If there is something appended, where am I allowing this to happen in the
    code below?
    >
    using System;
    using System.Xml;
    using System.Collecti ons.Generic;
    using System.Text;
    using System.Collecti ons;
    using System.Diagnost ics;
    using Microsoft.RuleE ngine;
    >
    namespace AL.TechSvcs.Pro curement.Suppor t
    {
    >
    public class BusinessRulesVe rification
    {
    public BusinessRulesVe rification()
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification ASSERTED");
    }
    >
    >
    public static string VerifyPOLineUni que(TypedXmlDoc ument rootNode,
    string PoNum, string xpath, string xLineNum)
    {
    XmlNodeList PoLines;
    >
    try
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: VerifyPOLineUni que STARTED");
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: PO NUM = " + PoNum);
    >
    PoLines =
    rootNode.Docume nt.SelectNodes( String.Format(x path, PoNum));
    >
    if (PoLines.Count 0)
    {
    >
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: PO lines 0");
    >
    //PUT MATCHING PO NUMBERS IN AN ARRAY
    ArrayList arrLineNums = new ArrayList();
    foreach (XmlNode node in PoLines)
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: looping thru lines");
    >
    >
    arrLineNums.Add (node.SelectSin gleNode(xLineNu m).InnerText);
    }
    >
    int i, j;
    >
    for (i = 0; i < arrLineNums.Cou nt - 1; i++)
    {
    for (j = i + 1; j < arrLineNums.Cou nt; j++)
    {
    if (arrLineNums[i].Equals(arrLine Nums[j]))
    {
    >
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: found non-unique line !!");
    >
    return "False";
    }
    }
    }
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: all lines are unique");
    >
    return "True";
    }
    else
    {
    Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
    BusinessRulesVe rification :: no PO lines found");
    return string.Empty;
    }
    }
    >
    catch (Exception e)
    {
    Debug.WriteLine (exception.ToSt ring());
    EventLog.WriteE ntry("Biztalk", String.Format(" Error occured
    when trying to find unique PO lines. Return empty string"),
    EventLogEntryTy pe.Error);
    throw e;
    }
    >
    }
    }
    }
    >
    >
    If anyone has seen this or knows what I am doing wrong, please help.
    >
    Thanks,
    >
    BA
    >

    Comment

    • BA

      #3
      Re: C# Static string appending problem.


      Nicholas,

      Thanks for having a look. Good suggestion about the throw, I will use it.

      Regarding the content. I am 100% sure that the data going in is a single
      instance. It would break in BizTalk with a host of errors such as multiple
      root nodes, etc and would also break in the business rules engine where this
      code is called. To be 100% sure I wrote out all the input statements in the
      first line of code to see what was there and they loooked normal.
      Additionally, notice how the "assert" statement which should appear first
      only appears first in the first pass. The remaining passes have something
      built up which is being dumped out when the code executes multiple times.

      I just cant figure out what is causing this.

      Do you have any other suggestions about what could be causing this?

      Thanks,
      BA



      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:e3FYsV%23b HHA.2120@TK2MSF TNGP03.phx.gbl. ..
      BA,
      >
      It doesn't look like you are doing anything (like storing a static
      variable) which would cause this to happen. Because of that, I would have
      to assume that your xpath expression that is being passed to the method is
      producing duplicate lines, or your XML document has the extra lines the
      second time around.
      >
      In other words, it's not the code, it's the input.
      >
      One thing I did notice, in your try/catch block, you have the line
      "throw e". You should change that to just "throw" so that the original
      stack trace information is retained, unless you ^want^ the stack trace
      information to start from the place where you re-throw the exception.
      >
      Hope this helps.
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "BA" <biztalk.archit ect@gmail.comwr ote in message
      news:%23AH9SM%2 3bHHA.4872@TK2M SFTNGP03.phx.gb l...
      >Hello,
      >>
      >I have a very strange code behavior that I cannot make heads or tails of:
      >>
      >I have c# code being executed in BizTalk assemblies which is acting very
      >strangely.
      >>
      >In my BizTalk process I call a static method:
      >>
      > public static string ValidateMessage (params...)
      >>
      >When I call this method the FIRST TIME, everything is fine, and the
      >DebugView outputs the following...
      >>
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ASSERTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ::
      >VerifyPOLineUn ique STARTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO NUM =
      >V3600063000010 00
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO lines
      > 0
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: all lines
      >are unique
      >>
      >>
      >>
      >>
      >Then it gets strange.... when I execute it a second time, I get:
      >>
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ::
      >VerifyPOLineUn ique STARTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO NUM =
      >V3600063000010 00
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO lines
      > 0
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: all lines
      >are unique
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ASSERTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ::
      >VerifyPOLineUn ique STARTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO NUM =
      >V3600063000010 00
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO lines
      > 0
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: all lines
      >are unique
      >>
      >>
      >A third time I get:
      >>
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ::
      >VerifyPOLineUn ique STARTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO NUM =
      >V3600063000010 00
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO lines
      > 0
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: all lines
      >are unique
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ::
      >VerifyPOLineUn ique STARTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO NUM =
      >V3600063000010 00
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO lines
      > 0
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: all lines
      >are unique
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ASSERTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification ::
      >VerifyPOLineUn ique STARTED
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO NUM =
      >V3600063000010 00
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: PO lines
      > 0
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: looping
      >thru lines
      >AL.TechSvcs.Pr ocurement.Suppo rt :: BusinessRulesVe rification :: all lines
      >are unique
      >>
      >>
      >And so on... It keeps piggy-backing these past method calls and I don't
      >know
      >why!
      >>
      >If I restart the BizTalk host, the first call behaves normally as
      >described above and then this problem begins again.
      >>
      >Someone suggested there was something static is being appended, but I
      >cant see it in the code. If you see something, please let me know. The
      >reason I
      >tend to agree is because the line "AL.TechSvcs.Pr ocurement.Suppo rt ::
      >BusinessRulesV erification ASSERTED " appears 2/3 of the way thru and its
      >the
      >very first thing which is done when the code is executed. It does not
      >appear that the logic is executing 3x, just the output to the debug view.
      >>
      >If there is something appended, where am I allowing this to happen in the
      >code below?
      >>
      >using System;
      >using System.Xml;
      >using System.Collecti ons.Generic;
      >using System.Text;
      >using System.Collecti ons;
      >using System.Diagnost ics;
      >using Microsoft.RuleE ngine;
      >>
      >namespace AL.TechSvcs.Pro curement.Suppor t
      >{
      >>
      > public class BusinessRulesVe rification
      > {
      > public BusinessRulesVe rification()
      > {
      > Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
      >BusinessRulesV erification ASSERTED");
      > }
      >>
      >>
      > public static string VerifyPOLineUni que(TypedXmlDoc ument rootNode,
      >string PoNum, string xpath, string xLineNum)
      > {
      > XmlNodeList PoLines;
      >>
      > try
      > {
      > Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
      >BusinessRulesV erification :: VerifyPOLineUni que STARTED");
      > Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
      >BusinessRulesV erification :: PO NUM = " + PoNum);
      >>
      > PoLines =
      >rootNode.Docum ent.SelectNodes (String.Format( xpath, PoNum));
      >>
      > if (PoLines.Count 0)
      > {
      >>
      > Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
      >BusinessRulesV erification :: PO lines 0");
      >>
      > //PUT MATCHING PO NUMBERS IN AN ARRAY
      > ArrayList arrLineNums = new ArrayList();
      > foreach (XmlNode node in PoLines)
      > {
      > Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort
      >:: BusinessRulesVe rification :: looping thru lines");
      >>
      >>
      >arrLineNums.Ad d(node.SelectSi ngleNode(xLineN um).InnerText);
      > }
      >>
      > int i, j;
      >>
      > for (i = 0; i < arrLineNums.Cou nt - 1; i++)
      > {
      > for (j = i + 1; j < arrLineNums.Cou nt; j++)
      > {
      > if (arrLineNums[i].Equals(arrLine Nums[j]))
      > {
      >>
      >Debug.WriteLin e("AL.TechSvcs. Procurement.Sup port ::
      >BusinessRulesV erification :: found non-unique line !!");
      >>
      > return "False";
      > }
      > }
      > }
      > Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
      >BusinessRulesV erification :: all lines are unique");
      >>
      > return "True";
      > }
      > else
      > {
      > Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
      >BusinessRulesV erification :: no PO lines found");
      > return string.Empty;
      > }
      > }
      >>
      > catch (Exception e)
      > {
      > Debug.WriteLine (exception.ToSt ring());
      > EventLog.WriteE ntry("Biztalk", String.Format(" Error
      >occured when trying to find unique PO lines. Return empty string"),
      >EventLogEntryT ype.Error);
      > throw e;
      > }
      >>
      > }
      > }
      >}
      >>
      >>
      >If anyone has seen this or knows what I am doing wrong, please help.
      >>
      >Thanks,
      >>
      >BA
      >>
      >
      >

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: C# Static string appending problem.

        BA,

        That's the thing, I see no static members, and no recursive calls, so it
        looks fine to me.

        Can't you run this through a debugger and see what is going on?


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "BA" <biztalk.archit ect@gmail.comwr ote in message
        news:uvM%23Xh%2 3bHHA.4720@TK2M SFTNGP04.phx.gb l...
        >
        Nicholas,
        >
        Thanks for having a look. Good suggestion about the throw, I will use it.
        >
        Regarding the content. I am 100% sure that the data going in is a single
        instance. It would break in BizTalk with a host of errors such as
        multiple root nodes, etc and would also break in the business rules engine
        where this code is called. To be 100% sure I wrote out all the input
        statements in the first line of code to see what was there and they
        loooked normal. Additionally, notice how the "assert" statement which
        should appear first only appears first in the first pass. The remaining
        passes have something built up which is being dumped out when the code
        executes multiple times.
        >
        I just cant figure out what is causing this.
        >
        Do you have any other suggestions about what could be causing this?
        >
        Thanks,
        BA
        >
        >
        >
        "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
        in message news:e3FYsV%23b HHA.2120@TK2MSF TNGP03.phx.gbl. ..
        >BA,
        >>
        > It doesn't look like you are doing anything (like storing a static
        >variable) which would cause this to happen. Because of that, I would
        >have to assume that your xpath expression that is being passed to the
        >method is producing duplicate lines, or your XML document has the extra
        >lines the second time around.
        >>
        > In other words, it's not the code, it's the input.
        >>
        > One thing I did notice, in your try/catch block, you have the line
        >"throw e". You should change that to just "throw" so that the original
        >stack trace information is retained, unless you ^want^ the stack trace
        >information to start from the place where you re-throw the exception.
        >>
        > Hope this helps.
        >>
        >>
        >--
        > - Nicholas Paldino [.NET/C# MVP]
        > - mvp@spam.guard. caspershouse.co m
        >>
        >"BA" <biztalk.archit ect@gmail.comwr ote in message
        >news:%23AH9SM% 23bHHA.4872@TK2 MSFTNGP03.phx.g bl...
        >>Hello,
        >>>
        >>I have a very strange code behavior that I cannot make heads or tails
        >>of:
        >>>
        >>I have c# code being executed in BizTalk assemblies which is acting very
        >>strangely.
        >>>
        >>In my BizTalk process I call a static method:
        >>>
        >> public static string ValidateMessage (params...)
        >>>
        >>When I call this method the FIRST TIME, everything is fine, and the
        >>DebugView outputs the following...
        >>>
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ASSERTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ::
        >>VerifyPOLineU nique STARTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO NUM =
        >>V360006300001 000
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO lines
        >> 0
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: all
        >>lines are unique
        >>>
        >>>
        >>>
        >>>
        >>Then it gets strange.... when I execute it a second time, I get:
        >>>
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ::
        >>VerifyPOLineU nique STARTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO NUM =
        >>V360006300001 000
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO lines
        >> 0
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: all
        >>lines are unique
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ASSERTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ::
        >>VerifyPOLineU nique STARTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO NUM =
        >>V360006300001 000
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO lines
        >> 0
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: all
        >>lines are unique
        >>>
        >>>
        >>A third time I get:
        >>>
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ::
        >>VerifyPOLineU nique STARTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO NUM =
        >>V360006300001 000
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO lines
        >> 0
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: all
        >>lines are unique
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ::
        >>VerifyPOLineU nique STARTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO NUM =
        >>V360006300001 000
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO lines
        >> 0
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: all
        >>lines are unique
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ASSERTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification ::
        >>VerifyPOLineU nique STARTED
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO NUM =
        >>V360006300001 000
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: PO lines
        >> 0
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: looping
        >>thru lines
        >>AL.TechSvcs.P rocurement.Supp ort :: BusinessRulesVe rification :: all
        >>lines are unique
        >>>
        >>>
        >>And so on... It keeps piggy-backing these past method calls and I don't
        >>know
        >>why!
        >>>
        >>If I restart the BizTalk host, the first call behaves normally as
        >>described above and then this problem begins again.
        >>>
        >>Someone suggested there was something static is being appended, but I
        >>cant see it in the code. If you see something, please let me know. The
        >>reason I
        >>tend to agree is because the line "AL.TechSvcs.Pr ocurement.Suppo rt ::
        >>BusinessRules Verification ASSERTED " appears 2/3 of the way thru and its
        >>the
        >>very first thing which is done when the code is executed. It does not
        >>appear that the logic is executing 3x, just the output to the debug
        >>view.
        >>>
        >>If there is something appended, where am I allowing this to happen in
        >>the code below?
        >>>
        >>using System;
        >>using System.Xml;
        >>using System.Collecti ons.Generic;
        >>using System.Text;
        >>using System.Collecti ons;
        >>using System.Diagnost ics;
        >>using Microsoft.RuleE ngine;
        >>>
        >>namespace AL.TechSvcs.Pro curement.Suppor t
        >>{
        >>>
        >> public class BusinessRulesVe rification
        >> {
        >> public BusinessRulesVe rification()
        >> {
        >> Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
        >>BusinessRules Verification ASSERTED");
        >> }
        >>>
        >>>
        >> public static string VerifyPOLineUni que(TypedXmlDoc ument
        >>rootNode, string PoNum, string xpath, string xLineNum)
        >> {
        >> XmlNodeList PoLines;
        >>>
        >> try
        >> {
        >> Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
        >>BusinessRules Verification :: VerifyPOLineUni que STARTED");
        >> Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
        >>BusinessRules Verification :: PO NUM = " + PoNum);
        >>>
        >> PoLines =
        >>rootNode.Docu ment.SelectNode s(String.Format (xpath, PoNum));
        >>>
        >> if (PoLines.Count 0)
        >> {
        >>>
        >> Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
        >>BusinessRules Verification :: PO lines 0");
        >>>
        >> //PUT MATCHING PO NUMBERS IN AN ARRAY
        >> ArrayList arrLineNums = new ArrayList();
        >> foreach (XmlNode node in PoLines)
        >> {
        >> Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort
        >>:: BusinessRulesVe rification :: looping thru lines");
        >>>
        >>>
        >>arrLineNums.A dd(node.SelectS ingleNode(xLine Num).InnerText) ;
        >> }
        >>>
        >> int i, j;
        >>>
        >> for (i = 0; i < arrLineNums.Cou nt - 1; i++)
        >> {
        >> for (j = i + 1; j < arrLineNums.Cou nt; j++)
        >> {
        >> if (arrLineNums[i].Equals(arrLine Nums[j]))
        >> {
        >>>
        >>Debug.WriteLi ne("AL.TechSvcs .Procurement.Su pport ::
        >>BusinessRules Verification :: found non-unique line !!");
        >>>
        >> return "False";
        >> }
        >> }
        >> }
        >> Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
        >>BusinessRules Verification :: all lines are unique");
        >>>
        >> return "True";
        >> }
        >> else
        >> {
        >> Debug.WriteLine ("AL.TechSvcs.P rocurement.Supp ort ::
        >>BusinessRules Verification :: no PO lines found");
        >> return string.Empty;
        >> }
        >> }
        >>>
        >> catch (Exception e)
        >> {
        >> Debug.WriteLine (exception.ToSt ring());
        >> EventLog.WriteE ntry("Biztalk", String.Format(" Error
        >>occured when trying to find unique PO lines. Return empty string"),
        >>EventLogEntry Type.Error);
        >> throw e;
        >> }
        >>>
        >> }
        >> }
        >>}
        >>>
        >>>
        >>If anyone has seen this or knows what I am doing wrong, please help.
        >>>
        >>Thanks,
        >>>
        >>BA
        >>>
        >>
        >>
        >
        >

        Comment

        • rossum

          #5
          Re: C# Static string appending problem.

          On Mon, 26 Mar 2007 16:12:24 -0400, "BA" <biztalk.archit ect@gmail.com>
          wrote:
          >In my BizTalk process I call a static method:
          >
          public static string ValidateMessage (params...)
          If the method is static, and you are talking about a static string in
          your title, then you might need to clear things either after you have
          finished a run, or before you start the next run. Keeping an
          inadvertent copy of the data from a previous run would seem likely to
          give the symptoms you are describing.

          rossum

          Comment

          Working...