Bizarre C# behavior

B

BA

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...

Validate ASSERTED
Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines


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

Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines
Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines

A third time I get:

Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines
Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines
Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines


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.

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

Thanks,

BA
 
J

Jon Skeet [C# MVP]

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.

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

Are the debug lines from your code? If so, I suggest you add a stack
trace to the output.
 
B

BA

Jon Skeet said:
Are the debug lines from your code? If so, I suggest you add a stack
trace to the output.

--

Jon,

Thanks for the reply.

I am not getting an error, the code executes fine, just too many times. I
am under the impression the stack trace is dumped when an exception is
thrown, if not, how do I dump the trace to the debug view?

BA
 
J

Jon Skeet [C# MVP]

BA said:
I am not getting an error, the code executes fine, just too many times. I
am under the impression the stack trace is dumped when an exception is
thrown, if not, how do I dump the trace to the debug view?

Create a new instance of StackTrace, and call ToString() on it - then
write that out to the debug view in the same way you do the other
lines.
 
B

Bruce Wood

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...

Validate ASSERTED
Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines

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

Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines
Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines

A third time I get:

Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines
Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines
Validate :: ValidateMessage STARTED
Validate :: looping thru lines
Validate :: looping thru lines

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.

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

We would need to see the code that writes these lines out, and any
variable declarations involved.

The first question that occurred to me is, "Is it really running the
method once, then twice, then three times, or is the output stored in
a static StringBuilder and each call just appends output?" In other
words, are there really three calls the third time, or are you just
seeing one new call's worth of output appended to the output from the
previous two calls?
 
B

BA

Hi,

I doubt it. My code is rather simple. If there was a way to check, I would
be grateful.

BA
 
B

BA

Bruce Wood said:
We would need to see the code that writes these lines out, and any
variable declarations involved.

The first question that occurred to me is, "Is it really running the
method once, then twice, then three times, or is the output stored in
a static StringBuilder and each call just appends output?" In other
words, are there really three calls the third time, or are you just
seeing one new call's worth of output appended to the output from the
previous two calls?

I also considered whether 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.Procurement.Support ::
BusinessRulesVerification ASSERTED " appears 2/3 of the way thru and its the
very first thing which is done when the code is executed.

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


Here is the output from the debug view and the code below..................


AL.TechSvcs.Procurement.Support :: BusinessRulesVerification ::
VerifyPOLineUnique STARTED
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: PO NUM =
V360006300001000
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: PO lines > 0
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: all lines
are unique
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification ::
VerifyPOLineUnique STARTED
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: PO NUM =
V360006300001000
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: PO lines > 0
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: all lines
are unique
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification ASSERTED
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification ::
VerifyPOLineUnique STARTED
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: PO NUM =
V360006300001000
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: PO lines > 0
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: looping thru
lines
AL.TechSvcs.Procurement.Support :: BusinessRulesVerification :: all lines
are unique



And the code..................


using System;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Diagnostics;
using Microsoft.RuleEngine;

namespace AL.TechSvcs.Procurement.Support
{

public class BusinessRulesVerification
{
public BusinessRulesVerification()
{
Debug.WriteLine("AL.TechSvcs.Procurement.Support ::
BusinessRulesVerification ASSERTED");
}


public static string VerifyPOLineUnique(TypedXmlDocument rootNode,
string PoNum, string xpath, string xLineNum)
{
XmlNodeList PoLines;

try
{
Debug.WriteLine("AL.TechSvcs.Procurement.Support ::
BusinessRulesVerification :: VerifyPOLineUnique STARTED");
Debug.WriteLine("AL.TechSvcs.Procurement.Support ::
BusinessRulesVerification :: PO NUM = " + PoNum);

PoLines = rootNode.Document.SelectNodes(String.Format(xpath,
PoNum));

if (PoLines.Count > 0)
{

Debug.WriteLine("AL.TechSvcs.Procurement.Support ::
BusinessRulesVerification :: PO lines > 0");

//PUT MATCHING PO NUMBERS IN AN ARRAY
ArrayList arrLineNums = new ArrayList();
foreach (XmlNode node in PoLines)
{
Debug.WriteLine("AL.TechSvcs.Procurement.Support ::
BusinessRulesVerification :: looping thru lines");

arrLineNums.Add(node.SelectSingleNode(xLineNum).InnerText);
}

int i, j;

for (i = 0; i < arrLineNums.Count - 1; i++)
{
for (j = i + 1; j < arrLineNums.Count; j++)
{
if (arrLineNums.Equals(arrLineNums[j]))
{
Debug.WriteLine("AL.TechSvcs.Procurement.Support
:: BusinessRulesVerification :: found non-unique line !!");

return "False";
}
}
}
Debug.WriteLine("AL.TechSvcs.Procurement.Support ::
BusinessRulesVerification :: all lines are unique");

return "True";
}
else
{
Debug.WriteLine("AL.TechSvcs.Procurement.Support ::
BusinessRulesVerification :: no PO lines found");
return string.Empty;
}
}

catch (Exception e)
{
Debug.WriteLine(exception.ToString());
EventLog.WriteEntry("Biztalk", String.Format("Error occured
when trying to find unique PO lines. Return empty string"),
EventLogEntryType.Error);
throw e;
}

}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top