Question



Me and some of my colleagues are working on a project together, and have encountered a weird issue we can't manage to fix.
The project involves the creation of a VNC connection between a client and a server, and is written in C# (we're using Visual Studio 2010). We're using the VNCSharp library for the client.
The issue I speak of is that once we start the connection with the server, an ArgumentException is thrown.
Some of the information supplied was this:

********** Exception Text **********
System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at VncSharp.RemoteDesktop.SetupDesktop()
at VncSharp.RemoteDesktop.Initialize()
at VncSharp.RemoteDesktop.Connect(String host, Int32 display, Boolean viewOnly, Boolean scaled)
at VncSharp.RemoteDesktop.Connect(String host)
at RemoteDesktopTest.Form2.startConnection()

Another weird thing about this is that it only occures some of the times, whereas in others it works perfectly well. Specifically, it always works when run in debug mode (i.e, when we run the program line-by-line using F11), and either works or doesn't work when run regularly (i.e Ctrl+F5), without any pattern we could recognize.

We would be really grateful for any and all help; if there are any details I can add that would assist in the answering of this question, please let me know. Additionally, I apologize for any grammar/spelling mistakes; English is not my first language... and I also apologize if something about this question is not alright. We're all beginners and this is our first "big project", so this is also my first time asking a question in Stack Overflow.

EDIT:
There are some parts of the code that are potentially relevant.
These are the lines of code automatically generated after we added the VncSharp control to the form and customized its settings:

this.remoteDesktop1 = new VncSharp.RemoteDesktop();

this.remoteDesktop1.AutoScroll = true;
this.remoteDesktop1.AutoScrollMinSize = new System.Drawing.Size(608, 427);
this.remoteDesktop1.Dock = System.Windows.Forms.DockStyle.Fill;
this.remoteDesktop1.Location = new System.Drawing.Point(0, 0);
this.remoteDesktop1.Name = "remoteDesktop1";
this.remoteDesktop1.Size = new System.Drawing.Size(1113, 580);
this.remoteDesktop1.TabIndex = 1;

This is the line of code in which I call the Connect method, while IP is simply the string taken from a text box:

remoteDesktop1.Connect(this.IP);

These are from the method which handles the ConnectComplete event (e is the EventArgs object passed to the method):

this.Location = new Point(0,0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
this.remoteDesktop1.Size = new System.Drawing.Size(e.DesktopWidth, e.DesktopHeight);

Aside from the line in which the Disconnect method is called, we've written literally no other lines of code that deal with this object. If I'll realize I'd forgotten something, I'll edit again and add it. Also, if there's anything specific in the code I should add here, please let me know.

Was it helpful?

Solution

The issue was related to timing, it seems.
Out of debug mode, the program ran too fast and those width and height variable didn't have their values updated.
Luckily, VncSharp is open source, so I could add my own line and leave it in a loop as long as either of those two variables still has its default value, and now it works.

Thanks for the help, everyone :)

OTHER TIPS

Had the same problem. For me it worked to compile the vncsharp solution in debug mode.

In RfbProtocol line 398 (first line of the ReadServerInit method), I transformed

int w = Reader.ReadUInt16();

to

int w = 0;
while (w == 0)
    w = Reader.ReadUInt16();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top