AdrianSzymczak / jabber-net

Automatically exported from code.google.com/p/jabber-net
0 stars 0 forks source link

Stream Error occurs in Release build, but not in Debug build - when connecting to google talk #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the product are you using? On what operating system?

JabberNet-2.1.0.710 (source) / Windows Vista / C# Compiler 3.5.21022.8
(Visual Studio 2008)

What steps will reproduce the problem?

1. Run (Release build) "ConsoleClient.exe /j:myuser@gmail.com /p:mypassword"

What is the expected output? What do you see instead?

DEBUG VERSION output (result as expected):
    ...
    SENT: <iq id="JN_1" type="set" to="gmail.com"><b...
    ...

RELEASE VERSION:
    ...
    SENT: <iq id="JN_1" type="" to="gmail.com"><bind...
    RECV: <stream:error><not-authorized xmlns="urn:i...
    Stream ERROR: <stream:error xmlns:stream="http:/...
    ...

Note that the type attribute is null in the release version.  This is the
cause of the error shown in the output above.  It was also causing my GUI
client to lose connection with the server.

I traced the problem to the fact that in the release build the string
representation of an enum value was not being returned as expected because
a crucial piece of code was inside a Debug.Assert call.

To fix the problem on my machine I modified the Jabber-Net source code in
the ToString method of the EnumParser class
("/jabber/protocol/EnumParser.cs") to bring the TryGetValue call outside of
Debug.Assert.

  Original Code :
     public static string ToString(object value)
     {
         ...
         Dictionary<object, string> map = GetStringHash(t);
         string val = null;
         Debug.Assert(map.TryGetValue(value, out val));
         return val;
     }

  Modified Code:

     public static string ToString(object value)
     {
         ...
         Dictionary<object, string> map = GetStringHash(t);
         string val = null;
         bool valueWasRetrieved = map.TryGetValue(value, out val);
         Debug.Assert(valueWasRetrieved);
         return val;
     }

While this fixed the problem for me I do wonder why no one else seems to
have the same problem.

Original issue reported on code.google.com by andy1...@gmail.com on 12 Aug 2008 at 10:32

GoogleCodeExporter commented 9 years ago
I encountered the same issue.  For good measure I searched through the
2005-jabber-net and netlib.Dns projects to make sure that no critical code was
contained in Debug statements, and it looks good.  If I had to guess as to why 
no one
else is reporting it, maybe no one is switching to Release mode to build?

Original comment by csam...@gmail.com on 31 Aug 2008 at 10:04

GoogleCodeExporter commented 9 years ago
Duh.  I *do* know better than to have side-effects in my asserts, but you 
couldn't 
tell from this code.  Fixed.

Original comment by hil...@gmail.com on 2 Sep 2008 at 9:34