Existence of “Add” Function causes WCF to Fail
-
I had a class
ClusterHazardLocations
which inherited some levels down fromIEnumerable
. In case of an alarm, anAlarmInfo
object is transferred from a sensor device via WCF to some other computer showing the information to the user. ThatAlarmInfo
has anIHazardLocations
property, and in this case it was aClusterHazardLocations
object. It used to work. Then I added a simple function to thatClusterHazardLocations
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 anAdd
method and the class does not derive from aList
or similar base class. After renaming theAdd
method toAddHazardLocation
, 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(); }
-
I had a class
ClusterHazardLocations
which inherited some levels down fromIEnumerable
. In case of an alarm, anAlarmInfo
object is transferred from a sensor device via WCF to some other computer showing the information to the user. ThatAlarmInfo
has anIHazardLocations
property, and in this case it was aClusterHazardLocations
object. It used to work. Then I added a simple function to thatClusterHazardLocations
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 anAdd
method and the class does not derive from aList
or similar base class. After renaming theAdd
method toAddHazardLocation
, 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(); }
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.
-
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.
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!
-
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!
I meant a simple repro of the issue rather than the thing itself.
-
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!
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!
-
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!
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!
-
I had a class
ClusterHazardLocations
which inherited some levels down fromIEnumerable
. In case of an alarm, anAlarmInfo
object is transferred from a sensor device via WCF to some other computer showing the information to the user. ThatAlarmInfo
has anIHazardLocations
property, and in this case it was aClusterHazardLocations
object. It used to work. Then I added a simple function to thatClusterHazardLocations
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 anAdd
method and the class does not derive from aList
or similar base class. After renaming theAdd
method toAddHazardLocation
, 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(); }
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