Click here to Skip to main content
16,020,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: BackGroundWorker gives runtime error Pin
Eddy Vluggen11-Feb-21 14:21
professionalEddy Vluggen11-Feb-21 14:21 
QuestionMonitor data using C# and ESP8266 Pin
pinout_19-Feb-21 1:56
pinout_19-Feb-21 1:56 
AnswerRe: Monitor data using C# and ESP8266 Pin
OriginalGriff9-Feb-21 2:20
mveOriginalGriff9-Feb-21 2:20 
GeneralRe: Monitor data using C# and ESP8266 Pin
pinout_19-Feb-21 2:31
pinout_19-Feb-21 2:31 
AnswerRe: Monitor data using C# and ESP8266 Pin
Gerry Schmitz9-Feb-21 7:54
mveGerry Schmitz9-Feb-21 7:54 
QuestionSerialize File from one format(AMI ) to another(BAI2) format Pin
Sasikalav8-Feb-21 19:31
Sasikalav8-Feb-21 19:31 
AnswerRe: Serialize File from one format(AMI ) to another(BAI2) format Pin
OriginalGriff8-Feb-21 20:04
mveOriginalGriff8-Feb-21 20:04 
QuestionExistence of “Add” Function causes WCF to Fail Pin
Bernhard Hiller8-Feb-21 0:44
Bernhard Hiller8-Feb-21 0:44 
I had a class ClusterHazardLocations which inherited some levels down from IEnumerable<IHazardLocation>. 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:
C#
public interface IHazardLocation {}
public interface IHazardLocations : IEnumerable<IHazardLocation> {}
public interface IClusterHazardLocations : IHazardLocations { }

    [Serializable]
    public class ClusterHazardLocation : IClusterHazardLocation
    {
        public ICluster Cluster { get; }

        /// <summary>
        /// for serialization only!
        /// </summary>
        [UsedImplicitly]
        public ClusterHazardLocation()
        { }
        public ClusterHazardLocation(ICluster _cluster)
            : this()
        {
            Cluster = _cluster;
        }
    }

    [Serializable]
    public class ClusterHazardLocations : IClusterHazardLocations
    {
        [NotNull]
        private readonly List<IClusterHazardLocation> m_Locations;

        public ClusterHazardLocations()
        {
            m_Locations = new List<IClusterHazardLocation>();
        }
        public ClusterHazardLocations([NotNull] params IClusterHazardLocation[] _locations)
        {
            m_Locations = _locations.ToList();
        }
        public ClusterHazardLocations([NotNull] IEnumerable<IClusterHazardLocation> _locations)
        {
            m_Locations = _locations.ToList();
        }
        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable<IHazardLocation>)m_Locations).GetEnumerator();
        }
        public IEnumerator<IHazardLocation> GetEnumerator()
        {
            return ((IEnumerable<IHazardLocation>)m_Locations).GetEnumerator();
        }
        // rename to Add to cause WCF failure
        public void AddHazardLocation(IHazardLocation _other)
        {
            if (_other is IClusterHazardLocation tmp)
            {
                m_Locations.Add(tmp);
            }
        }
    }

Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!


modified 8-Feb-21 10:12am.

AnswerRe: Existence of “Add” Function causes WCF to Fail Pin
Pete O'Hanlon8-Feb-21 1:42
mvePete O'Hanlon8-Feb-21 1:42 
GeneralRe: Existence of “Add” Function causes WCF to Fail Pin
Bernhard Hiller8-Feb-21 2:10
Bernhard Hiller8-Feb-21 2:10 
GeneralRe: Existence of “Add” Function causes WCF to Fail Pin
Pete O'Hanlon8-Feb-21 2:12
mvePete O'Hanlon8-Feb-21 2:12 
GeneralRe: Existence of “Add” Function causes WCF to Fail Pin
OriginalGriff8-Feb-21 4:01
mveOriginalGriff8-Feb-21 4:01 
GeneralRe: Existence of “Add” Function causes WCF to Fail Pin
Bernhard Hiller8-Feb-21 4:03
Bernhard Hiller8-Feb-21 4:03 
AnswerRe: Existence of “Add” Function causes WCF to Fail Pin
Gerry Schmitz8-Feb-21 4:45
mveGerry Schmitz8-Feb-21 4:45 
QuestionHow to avoid progress bar freeze when calculations are performed in background? Pin
Alex Dunlop7-Feb-21 8:18
Alex Dunlop7-Feb-21 8:18 
GeneralRe: How to avoid progress bar freeze when calculations are performed in background? Pin
harold aptroot7-Feb-21 8:24
harold aptroot7-Feb-21 8:24 
GeneralRe: How to avoid progress bar freeze when calculations are performed in background? Pin
Alex Dunlop7-Feb-21 16:24
Alex Dunlop7-Feb-21 16:24 
AnswerRe: How to avoid progress bar freeze when calculations are performed in background? Pin
Gerry Schmitz7-Feb-21 10:19
mveGerry Schmitz7-Feb-21 10:19 
AnswerRe: How to avoid progress bar freeze when calculations are performed in background? Pin
Luc Pattyn7-Feb-21 17:18
sitebuilderLuc Pattyn7-Feb-21 17:18 
QuestionWinForm launching a console application Pin
picasso22-Feb-21 18:32
picasso22-Feb-21 18:32 
AnswerRe: WinForm launching a console application Pin
Gerry Schmitz2-Feb-21 18:36
mveGerry Schmitz2-Feb-21 18:36 
GeneralRe: WinForm launching a console application Pin
Dave Kreskowiak2-Feb-21 18:42
mveDave Kreskowiak2-Feb-21 18:42 
GeneralRe: WinForm launching a console application Pin
Gerry Schmitz3-Feb-21 6:20
mveGerry Schmitz3-Feb-21 6:20 
GeneralRe: WinForm launching a console application Pin
Dave Kreskowiak3-Feb-21 6:39
mveDave Kreskowiak3-Feb-21 6:39 
GeneralRe: WinForm launching a console application Pin
Gerry Schmitz3-Feb-21 6:59
mveGerry Schmitz3-Feb-21 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.