Click to See Complete Forum and Search --> : C-sharp Express Serial.IO.Ports.SerialPorts Issue


jsisson01
July 28th, 2009, 03:44 PM
Hi,

I'm new to programming in C#. Problem I'm getting is when compiling a program it is giving me a reference error. I'm not completely clear on how to fix it.

Error 1 The type 'System.IO.Ports.SerialPort' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll' and 'c:\Documents and Settings\Mobile1\Desktop\Snap_Library\Master\SerialPort.dll' C:\Documents and Settings\Mobile1\Desktop\Snap_Library\Master\Snap.cs 11 11 Master


I know about the whole removing the reference of the "SerialPort.dll" but it has required references within it. And I can't remove the system.dll reference either. Can anybody give me a clue on what to do?

Thanks,
Josh

RaleTheBlade
July 28th, 2009, 04:53 PM
You going to have to use one or the other. Judging from the message, a class with the name SerialPort exists in both System.IO.Ports namespaces in both files. You can only use one SerialPort class definition however. Seems like poor insight on whoever wrote the SerialPort.dll file or something... Or if the namespace is indeed different in the SerialPort.dll file, use the fully qualified name to the SerialPort class.

jsisson01
July 28th, 2009, 05:01 PM
I believe the program was written in 2003, I'm trying to modify a pre-existing program. I probably should have stated that, sorry. From my understanding, the system.dll doesn't have a specific reference the serialport.dll has, so even if I do remove the serialport.dll, I run into another error later on in the code.

RaleTheBlade
July 28th, 2009, 05:06 PM
system.dll should contain the namespace System.IO.Ports with the class SerialPort in that namespace. If you can remove the reference to the SerialPort.dll file it should fix the problem since your only referencing two libraries. I dont think Im understanding the problem, here is how I understand it:

You are referencing two libraries, system.dll and SerialPort.dll
Both of the files contain a namespace System.IO.Ports
Both of the files contain a class named SerialPort in that namespace
The compiler doesnt know which SerialPort class to use because the namespaces and class names are identical

Am I sort of correct? lol

BigEd781
July 28th, 2009, 05:11 PM
Rale is correct, just fully qualify the assembly name:


System.IO.Ports.SerialPort port1;
MyDLLNamespace.SerialPort port2; // works now because the compiler knows where to look for the type

jsisson01
July 29th, 2009, 09:11 AM
I think I'm confused.... I've attached the code to the message. Can one of you take a look at it and see? Thanks for the help either way though. Much appreciated.

vcdebugger
July 30th, 2009, 12:47 AM
try using

private System.IO.Ports.SerialPort serialPort;

instead of just SerialPort serialPort; so that i might avoid refering to the other local snap library on the desktop.

jsisson01
July 31st, 2009, 11:22 AM
That won't work because the class exists in both DLL's still. :-|

BigEd781
July 31st, 2009, 05:07 PM
...

So you are saying that both dll's declare the System.IO.Ports namespace? I find that very hard to believe. If your third party dll does that then it was written by a group of morons, seriously.

RaleTheBlade
August 1st, 2009, 09:23 AM
...

So you are saying that both dll's declare the System.IO.Ports namespace? I find that very hard to believe. If your third party dll does that then it was written by a group of morons, seriously.

Thats what I said, but if it were written in the .NET 1.1 days its quite possible. Sorry to say but if this is the case you probably wont be able to use that library. Youll either have to find another 3rd party library or roll your own. I always opt for rolling my own, I dont trust alot of 3rd party libraries for this very reason.