richardschneider / net-mdns

Simple multicast DNS
MIT License
232 stars 81 forks source link

Internal InvalidOperationException occurs #105

Open dittodhole opened 3 years ago

dittodhole commented 3 years ago

Hi there,

<PackageReference Include="Makaretu.Dns.Multicast">
  <Version>0.27.0</Version>
</PackageReference>

I am unsure whether it occurs on receiver's or sender's site:

Class:   Makaretu.Dns.MulticastService
Method:  Void OnDnsMessage(System.Object, System.Net.Sockets.UdpReceiveResult)
Level:     ERROR
Logger:  Makaretu.Dns.MulticastService

Message: Receive handler failed
System.InvalidOperationException: La collection a �t� modifi�e�; l'op�ration d'�num�ration peut ne pas s'ex�cuter.
   � System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   � System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   � System.Collections.Generic.List`1.Enumerator.MoveNext()
   � Makaretu.Dns.TXTRecord.WriteData(WireWriter writer)
   � Makaretu.Dns.ResourceRecord.Write(WireWriter writer)
   � Makaretu.Dns.Message.Write(WireWriter writer)
   � Makaretu.Dns.DnsObject.Length()
   � Makaretu.Dns.Message.Truncate(Int32 length)
   � Makaretu.Dns.MulticastService.SendAnswer(Message answer, Boolean checkDuplicate)
   � Makaretu.Dns.MulticastService.SendAnswer(Message answer, MessageEventArgs query, Boolean checkDuplicate)
   � Makaretu.Dns.ServiceDiscovery.OnQuery(Object sender, MessageEventArgs e)
   � Makaretu.Dns.MulticastService.OnDnsMessage(Object sender, UdpReceiveResult result)
Class:   Makaretu.Dns.MulticastService
Method:  Void OnDnsMessage(System.Object, System.Net.Sockets.UdpReceiveResult)
Level:     ERROR
Logger:  Makaretu.Dns.MulticastService

Message: Receive handler failed
System.AggregateException: Une ou plusieurs erreurs se sont produites. ---> System.InvalidOperationException: La collection a �t� modifi�e�; l'op�ration d'�num�ration peut ne pas s'ex�cuter.
   � System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   � System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   � System.Collections.Generic.List`1.Enumerator.MoveNext()
   � Makaretu.Dns.TXTRecord.WriteData(WireWriter writer)
   � Makaretu.Dns.ResourceRecord.GetData()
   � Makaretu.Dns.ResourceRecord.Equals(Object obj)
   � System.Collections.Generic.ObjectEqualityComparer`1.Equals(T x, T y)
   � System.Collections.Generic.List`1.Contains(T item)
   � Makaretu.Dns.Resolving.NameServer.<>c__DisplayClass12_0.<AddAdditionalRecords>b__1(ResourceRecord a)
   � System.Linq.Enumerable.<>c__DisplayClass6_0`1.<CombinePredicates>b__0(TSource x)
   � System.Linq.Enumerable.WhereListIterator`1.MoveNext()
   � System.Linq.Enumerable.<DistinctIterator>d__64`1.MoveNext()
   � System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   � System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   � Makaretu.Dns.Resolving.NameServer.AddAdditionalRecords(Message response)
   � Makaretu.Dns.Resolving.NameServer.AddAdditionalRecords(Message response)
   � Makaretu.Dns.Resolving.NameServer.AddAdditionalRecords(Message response)
   � Makaretu.Dns.Resolving.NameServer.<ResolveAsync>d__9.MoveNext()
--- Fin de la trace de la pile � partir de l'emplacement pr�c�dent au niveau duquel l'exception a �t� lev�e ---
   � System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   � System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   � Makaretu.Dns.Resolving.NameServer.<ResolveAsync>d__8.MoveNext()
   --- Fin de la trace de la pile d'exception interne ---
   � System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   � System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   � System.Threading.Tasks.Task`1.get_Result()
   � Makaretu.Dns.ServiceDiscovery.OnQuery(Object sender, MessageEventArgs e)
   � Makaretu.Dns.MulticastService.OnDnsMessage(Object sender, UdpReceiveResult result)
---> (Exception interne #0) System.InvalidOperationException: La collection a �t� modifi�e�; l'op�ration d'�num�ration peut ne pas s'ex�cuter.
   � System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   � System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   � System.Collections.Generic.List`1.Enumerator.MoveNext()
   � Makaretu.Dns.TXTRecord.WriteData(WireWriter writer)
   � Makaretu.Dns.ResourceRecord.GetData()
   � Makaretu.Dns.ResourceRecord.Equals(Object obj)
   � System.Collections.Generic.ObjectEqualityComparer`1.Equals(T x, T y)
   � System.Collections.Generic.List`1.Contains(T item)
   � Makaretu.Dns.Resolving.NameServer.<>c__DisplayClass12_0.<AddAdditionalRecords>b__1(ResourceRecord a)
   � System.Linq.Enumerable.<>c__DisplayClass6_0`1.<CombinePredicates>b__0(TSource x)
   � System.Linq.Enumerable.WhereListIterator`1.MoveNext()
   � System.Linq.Enumerable.<DistinctIterator>d__64`1.MoveNext()
   � System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   � System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   � Makaretu.Dns.Resolving.NameServer.AddAdditionalRecords(Message response)
   � Makaretu.Dns.Resolving.NameServer.AddAdditionalRecords(Message response)
   � Makaretu.Dns.Resolving.NameServer.AddAdditionalRecords(Message response)
   � Makaretu.Dns.Resolving.NameServer.<ResolveAsync>d__9.MoveNext()
--- Fin de la trace de la pile � partir de l'emplacement pr�c�dent au niveau duquel l'exception a �t� lev�e ---
   � System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   � System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   � Makaretu.Dns.Resolving.NameServer.<ResolveAsync>d__8.MoveNext()<---
twofingerrightclick commented 2 years ago

Si c'est toujours un problème pour toi, si te plait ajouter some sample code of how you are using the net-mdns library to give some context to the error messages.

dittodhole commented 2 years ago

I am just calling Advertise and QueryUnicastServiceInstances. At some point, mentioned exception is thrown in the event handler.