Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Object Type Casting problem

Object Type Casting problem

Scheduled Pinned Locked Moved C#
saleshelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    srivatsan24
    wrote on last edited by
    #1

    I have a class, let us say Customer which has a set of properties. I am using this class that is in a common dll in two different services (say Service1,Service2). Now i have a windows application (say WinApplication1)where i am adding reference to both the Services. So i have access to the Customer object in two differenct ways. 1) WinApplication1.Service1.Customer 2) WinApplication1.Service2.Customer In my application i want to get a customer object from this service and pass it into the other service as an input. But i am getting casting problem. It says "Cannot implicitly convert type WinApplication1.Service1.Customer to WinApplication1.Service2.Customer" Please let me know if there is a easy way to do this conversion? Srivatsan

    C 1 Reply Last reply
    0
    • S srivatsan24

      I have a class, let us say Customer which has a set of properties. I am using this class that is in a common dll in two different services (say Service1,Service2). Now i have a windows application (say WinApplication1)where i am adding reference to both the Services. So i have access to the Customer object in two differenct ways. 1) WinApplication1.Service1.Customer 2) WinApplication1.Service2.Customer In my application i want to get a customer object from this service and pass it into the other service as an input. But i am getting casting problem. It says "Cannot implicitly convert type WinApplication1.Service1.Customer to WinApplication1.Service2.Customer" Please let me know if there is a easy way to do this conversion? Srivatsan

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      You appear to have defined Customer twice. Once in each service. You should place Customer in its own Class Library project and then reference it from any other project that needs it. Assuming Customer is identical in each of the existing projects this should work fairly easily. However, if Customer in each of the existing projects, is the same in name only then you have a lot of work ahead of you to redesign your application.


      Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

      S 1 Reply Last reply
      0
      • C Colin Angus Mackay

        You appear to have defined Customer twice. Once in each service. You should place Customer in its own Class Library project and then reference it from any other project that needs it. Assuming Customer is identical in each of the existing projects this should work fairly easily. However, if Customer in each of the existing projects, is the same in name only then you have a lot of work ahead of you to redesign your application.


        Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

        S Offline
        S Offline
        srivatsan24
        wrote on last edited by
        #3

        The Customer Object is in a separate class library project only. I have referenced it in both the services. Now my win application is consuming both the service. Now i am getting the Customer object as an output of Service1 that has a datatype of Service1.Customer and when i try to pass it as an input to one of the methods in Service two that expects Service2.Customer, I am not able to do it. The contents of the object Customer are the same. Now what to do? Srivatsan -- modified at 7:00 Monday 9th April, 2007

        C 1 Reply Last reply
        0
        • S srivatsan24

          The Customer Object is in a separate class library project only. I have referenced it in both the services. Now my win application is consuming both the service. Now i am getting the Customer object as an output of Service1 that has a datatype of Service1.Customer and when i try to pass it as an input to one of the methods in Service two that expects Service2.Customer, I am not able to do it. The contents of the object Customer are the same. Now what to do? Srivatsan -- modified at 7:00 Monday 9th April, 2007

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          I'm confused. You now appear to have 3 definitions for a Customer object. You should only have one throughout your entire solution. You should be using only the customer object in the class library. You need to remove the definitions of Customer in the Services and use the Customer class in the class library instead. You can add the class library as a reference to each project that needs it. You can do that by right-clicking the project and selecting "Add Reference..." and going to the projects tab and choosing the class library project that contains the Customer class.


          Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

          S 1 Reply Last reply
          0
          • C Colin Angus Mackay

            I'm confused. You now appear to have 3 definitions for a Customer object. You should only have one throughout your entire solution. You should be using only the customer object in the class library. You need to remove the definitions of Customer in the Services and use the Customer class in the class library instead. You can add the class library as a reference to each project that needs it. You can do that by right-clicking the project and selecting "Add Reference..." and going to the projects tab and choosing the class library project that contains the Customer class.


            Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

            S Offline
            S Offline
            srivatsan24
            wrote on last edited by
            #5

            Hey i am doing as you are telling only. There are no multiple copies of the class. It is there in the common project(separate class library). But when you use the class by adding reference to the services then the wsdl of each and every service since it is in a different namespace will consider the same class as two different class files. Srivatsan

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups