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
  1. Home
  2. General Programming
  3. C#
  4. Existence of “Add” Function causes WCF to Fail

Existence of “Add” Function causes WCF to Fail

Scheduled Pinned Locked Moved C#
csharpwcfiotjsonquestion
7 Posts 4 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.
  • B Offline
    B Offline
    Bernhard Hiller
    wrote on last edited by
    #1

    I had a class ClusterHazardLocations which inherited some levels down from IEnumerable. In case of an alarm, an AlarmInfo object is transferred from a sensor device via WCF to some other computer showing the information to the user. That AlarmInfo has an IHazardLocations property, and in this case it was a ClusterHazardLocations object. It used to work. Then I added a simple function to that ClusterHazardLocations class: public void Add(IHazardLocation other). The mere existence of the function - even with an empty body - causes the WCF communication to fail. I do not understand that at all. After all, IEnumerable does not have an Add method and the class does not derive from a List or similar base class. After renaming the Add method to AddHazardLocation, everything worked again. Could you please explain how this odd behavior of WCF was caused? Edit: "a small project" with WCF... Ehm. But a small interface /class hierarchy:

    public interface IHazardLocation {}
    public interface IHazardLocations : IEnumerable {}
    public interface IClusterHazardLocations : IHazardLocations { }

    \[Serializable\]
    public class ClusterHazardLocation : IClusterHazardLocation
    {
        public ICluster Cluster { get; }
    
        /// /// for serialization only!
        /// 
        \[UsedImplicitly\]
        public ClusterHazardLocation()
        { }
        public ClusterHazardLocation(ICluster \_cluster)
            : this()
        {
            Cluster = \_cluster;
        }
    }
    
    \[Serializable\]
    public class ClusterHazardLocations : IClusterHazardLocations
    {
        \[NotNull\]
        private readonly List m\_Locations;
    
        public ClusterHazardLocations()
        {
            m\_Locations = new List();
        }
        public ClusterHazardLocations(\[NotNull\] params IClusterHazardLocation\[\] \_locations)
        {
            m\_Locations = \_locations.ToList();
        }
        public ClusterHazardLocations(\[NotNull\] IEnumerable \_locations)
        {
            m\_Locations = \_locations.ToList();
        }
        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)m\_Locations).GetEnumerator();
        }
    
    P L 2 Replies Last reply
    0
    • B Bernhard Hiller

      I had a class ClusterHazardLocations which inherited some levels down from IEnumerable. In case of an alarm, an AlarmInfo object is transferred from a sensor device via WCF to some other computer showing the information to the user. That AlarmInfo has an IHazardLocations property, and in this case it was a ClusterHazardLocations object. It used to work. Then I added a simple function to that ClusterHazardLocations class: public void Add(IHazardLocation other). The mere existence of the function - even with an empty body - causes the WCF communication to fail. I do not understand that at all. After all, IEnumerable does not have an Add method and the class does not derive from a List or similar base class. After renaming the Add method to AddHazardLocation, everything worked again. Could you please explain how this odd behavior of WCF was caused? Edit: "a small project" with WCF... Ehm. But a small interface /class hierarchy:

      public interface IHazardLocation {}
      public interface IHazardLocations : IEnumerable {}
      public interface IClusterHazardLocations : IHazardLocations { }

      \[Serializable\]
      public class ClusterHazardLocation : IClusterHazardLocation
      {
          public ICluster Cluster { get; }
      
          /// /// for serialization only!
          /// 
          \[UsedImplicitly\]
          public ClusterHazardLocation()
          { }
          public ClusterHazardLocation(ICluster \_cluster)
              : this()
          {
              Cluster = \_cluster;
          }
      }
      
      \[Serializable\]
      public class ClusterHazardLocations : IClusterHazardLocations
      {
          \[NotNull\]
          private readonly List m\_Locations;
      
          public ClusterHazardLocations()
          {
              m\_Locations = new List();
          }
          public ClusterHazardLocations(\[NotNull\] params IClusterHazardLocation\[\] \_locations)
          {
              m\_Locations = \_locations.ToList();
          }
          public ClusterHazardLocations(\[NotNull\] IEnumerable \_locations)
          {
              m\_Locations = \_locations.ToList();
          }
          IEnumerator IEnumerable.GetEnumerator()
          {
              return ((IEnumerable)m\_Locations).GetEnumerator();
          }
      
      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Is this something you can recreate with a simple dummy project? If it's something you could upload to github, I'd enjoy having a look at it.

      Advanced TypeScript Programming Projects

      B 1 Reply Last reply
      0
      • P Pete OHanlon

        Is this something you can recreate with a simple dummy project? If it's something you could upload to github, I'd enjoy having a look at it.

        Advanced TypeScript Programming Projects

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        Thanks for your help. Unfortunatey, it's too big... Do you have some similar situation some where: - a class which inherits IEnumberable, but does not derive from List/Array etc, instead contains a List - can be transferred via WCF - now add an "Add" method I am not sure if those are already all the required steps.

        Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

        P OriginalGriffO 2 Replies Last reply
        0
        • B Bernhard Hiller

          Thanks for your help. Unfortunatey, it's too big... Do you have some similar situation some where: - a class which inherits IEnumberable, but does not derive from List/Array etc, instead contains a List - can be transferred via WCF - now add an "Add" method I am not sure if those are already all the required steps.

          Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          I meant a simple repro of the issue rather than the thing itself.

          Advanced TypeScript Programming Projects

          1 Reply Last reply
          0
          • B Bernhard Hiller

            Thanks for your help. Unfortunatey, it's too big... Do you have some similar situation some where: - a class which inherits IEnumberable, but does not derive from List/Array etc, instead contains a List - can be transferred via WCF - now add an "Add" method I am not sure if those are already all the required steps.

            Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            What Pete is suggesting is a dummy project to prove where the fault lies: create a minimal sample that doesn't have the problem, add the Add method and see if it fails. If it does, put it up on Github for examination. If it doesn't ... then the Add addition is probably coincidental, and you broke something else at the same time!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            B 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              What Pete is suggesting is a dummy project to prove where the fault lies: create a minimal sample that doesn't have the problem, add the Add method and see if it fails. If it does, put it up on Github for examination. If it doesn't ... then the Add addition is probably coincidental, and you broke something else at the same time!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #6

              OriginalGriff wrote:

              the Add addition is probably coincidental, and you broke something else at the same time

              Absolutely sure: by renaming "Add" to "AddHazardLocation" the problem was solved. I did the analysis step by step - tedious minimal steps. Nothing else was changed at that moment.

              Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

              1 Reply Last reply
              0
              • B Bernhard Hiller

                I had a class ClusterHazardLocations which inherited some levels down from IEnumerable. In case of an alarm, an AlarmInfo object is transferred from a sensor device via WCF to some other computer showing the information to the user. That AlarmInfo has an IHazardLocations property, and in this case it was a ClusterHazardLocations object. It used to work. Then I added a simple function to that ClusterHazardLocations class: public void Add(IHazardLocation other). The mere existence of the function - even with an empty body - causes the WCF communication to fail. I do not understand that at all. After all, IEnumerable does not have an Add method and the class does not derive from a List or similar base class. After renaming the Add method to AddHazardLocation, everything worked again. Could you please explain how this odd behavior of WCF was caused? Edit: "a small project" with WCF... Ehm. But a small interface /class hierarchy:

                public interface IHazardLocation {}
                public interface IHazardLocations : IEnumerable {}
                public interface IClusterHazardLocations : IHazardLocations { }

                \[Serializable\]
                public class ClusterHazardLocation : IClusterHazardLocation
                {
                    public ICluster Cluster { get; }
                
                    /// /// for serialization only!
                    /// 
                    \[UsedImplicitly\]
                    public ClusterHazardLocation()
                    { }
                    public ClusterHazardLocation(ICluster \_cluster)
                        : this()
                    {
                        Cluster = \_cluster;
                    }
                }
                
                \[Serializable\]
                public class ClusterHazardLocations : IClusterHazardLocations
                {
                    \[NotNull\]
                    private readonly List m\_Locations;
                
                    public ClusterHazardLocations()
                    {
                        m\_Locations = new List();
                    }
                    public ClusterHazardLocations(\[NotNull\] params IClusterHazardLocation\[\] \_locations)
                    {
                        m\_Locations = \_locations.ToList();
                    }
                    public ClusterHazardLocations(\[NotNull\] IEnumerable \_locations)
                    {
                        m\_Locations = \_locations.ToList();
                    }
                    IEnumerator IEnumerable.GetEnumerator()
                    {
                        return ((IEnumerable)m\_Locations).GetEnumerator();
                    }
                
                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Creating "empty" interfaces seem questionable to start with.

                public interface IHazardLocation {}

                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                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