Dealing with WCF Error: Cannot create a service reference with namespace X because the name is already in use by an existing service reference, folder or file

If you get the above error when trying to add a WCF service reference that you have previously deleted then try:

  • deleting the Service References.DeviceService.Reference.cs.dll file you’ll find under obj\Debug\TempPE. 
  • deleting the service folder you’ll still find under Service References on disk, even though you deleted the reference in Visual Studio.
  • commenting out all references to the service’s namespace in your code
  • rebuilding

11 thoughts on “Dealing with WCF Error: Cannot create a service reference with namespace X because the name is already in use by an existing service reference, folder or file

  1. Thierry

    I had the same issue but I solved it in a different way:

    When adding the “Service Reference” click on the “Advanced…” button on the lower left side and by default the option “Reuse types in referenced assemblies” is selected, Deselect it, press “Ok” and that should do it 😉

    …Ok, I know almost a year later lol

    Reply
  2. Jason

    Thankyou, you helped me out. But in addition to your steps, I also removed my entire obj folder, also I removed my ‘Release’ folder from bin (leaving just the ‘Debug’).

    Reply
  3. Ben

    Hi
    The four steps above surely helped but the error still ocurred. I had to restart Visual Studio 2010 with the cleaned up project.

    Reply
  4. Jon

    Hi,

    The workaround mentioned above didn’t work for me. However, if I leave VS2010 and open my solution in Phone Studio Express (C:Program FilesMicrosoft Visual Studio 10.0Common7IDEVPDExpress.exe) a valid reference is made that can then be used back in VS2010.

    Cheers,

    Jon

    Reply
  5. Kostas

    Hi, the solution worked for me by following Damian’s instructions and additionally restarting all VS instances.

    Reply
  6. mrp

    So many years and the problem still floats around, even in VS2012.

    I tried all of the above, no luck, still get the same error.

    Here is what fixed it for me:
    (1) close visual studio.
    (2) in windows explorer browse to your solution folder, then open the project folder of the vs project where you want to add a reference.
    (3) inside the project folder theres a Service References subfolder with a folder for each service reference.
    (4) find the folder that has the same name as the name of the service reference you want to add; delete the folder.
    (5) Reopen visual studio and add the service reference. No problems

    Reply
  7. damian Post author

    Who’d have thought when I wrote this post in 2008 that it would still be getting hits – thanks for posting your solution!

    Reply
  8. Angel Rubio

    I don´t know if this can help You but it did to me.

    i have the Services working but in the file of the VS Project (.csproj) i need to add this lines:

    True
    True
    Reference.svcmap

    this way yo don´t need to add the service reference again just fix the VS project.
    Best regards 2017

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *