CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2009
    Posts
    4

    Question C-sharp Express Serial.IO.Ports.SerialPorts Issue

    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

  2. #2
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

    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.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  3. #3
    Join Date
    Jul 2009
    Posts
    4

    Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

    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.

  4. #4
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

    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
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

    Rale is correct, just fully qualify the assembly name:

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

  6. #6
    Join Date
    Jul 2009
    Posts
    4

    Smile Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

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

  7. #7
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

    try using

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

  8. #8
    Join Date
    Jul 2009
    Posts
    4

    Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

    That won't work because the class exists in both DLL's still. :-|

  9. #9
    Join Date
    Jun 2008
    Posts
    2,477

    Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

    ...

    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.

  10. #10
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: C-sharp Express Serial.IO.Ports.SerialPorts Issue

    Quote Originally Posted by BigEd781 View Post
    ...

    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.
    Last edited by RaleTheBlade; August 1st, 2009 at 09:28 AM.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured