.NET Components for Mobility

Bluetooth chat works in Visual Basic, not C#

Last post 06-29-2007 7:18 AM by matthewwebster. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-27-2007 7:24 PM

    Bluetooth chat works in Visual Basic, not C#

    Hi, again,

     I've converted the Visual Basic Bluetooth chat sample (as found in: ) using http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx into C#.  However, it runs perfectly, except that starting the BtListener fails at btlistener.Start();

    Would anyone know why this is?  I can post the code if necessary, along with proof that it bails on the .start().

    Regards,

     Matt.

  • 06-28-2007 5:13 AM In reply to

    Re: Bluetooth chat works in Visual Basic, not C#

    Hi, what specific exception occurs on Start()?

     Peter

    Peter Foot
    Microsoft Device Application Development MVP
    www.peterfoot.net | www.inthehand.com
  • 06-28-2007 7:27 AM In reply to

    Re: Bluetooth chat works in Visual Basic, not C#

    Well, the error is this:

    ReceiveLoop error (1): An error message cannot be displayed because an optional resource assmebly containing it cannot be found

    The code producing this is:

    public void receiveLoop()
    {
    int count = 0;
    try
    {
    string strReceived;
    btListener =
    new BluetoothListener(ServiceName); count++;
    btListener.Start(); count++;
    strReceived = receiveMessage(MAX_MESSAGE_SIZE); count++;
    while (listening)
    {
    //---keep on listening for new message
    if (strReceived != "")
    {
    this.Invoke(new EventHandler(UpdateTextBox)); count++;
    strReceived = receiveMessage(MAX_MESSAGE_SIZE); count++;
    }
    }
    }
    catch (Exception e)
    {
    MessageBox.Show("ReceiveLoop error (" + count + "): " + e.Message);
    }
    }

    I put the count++; in myself to see where the exception was being generated, as the error message itself is not very useful.  As you can see, it's occuring on the:

    btListener.Start(); count++;

    line, but any more than than I can't tell you.

    Regards,

     Matt. W.

  • 06-28-2007 11:59 AM In reply to

    Re: Bluetooth chat works in Visual Basic, not C#

    In NETCF the exception messages are included only in a separate assembly; it is included when running from the debugger or can be included manually (err link?).

    But seeing the exception type and the stack trace is probably enough, so either change e.Message to

        e.GetType().FullName + "\r\n" + e.StackTrace

    or just to

        e

    (which calls Exception.ToString() which includes the type, the message, the stack trace and any inner exception(s)... , see http://msdn2.microsoft.com/en-us/library/system.exception.tostring.aspx)

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 06-29-2007 7:18 AM In reply to

    Re: Bluetooth chat works in Visual Basic, not C#

    Found the answer in this post: http://32feet.net/forums/p/1195/3530.aspx#3530

    Basically, when creating a new device project it has to be .NET CF v1.0, not 2 (v2 shows up in Add Projects without a number).

    All works now :)

    Matt.

Page 1 of 1 (5 items)
Copyright © 2001-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.