{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-event-hubs-dotnet/issues/274","repository_url":"https://api.github.com/repos/Azure/azure-event-hubs-dotnet","labels_url":"https://api.github.com/repos/Azure/azure-event-hubs-dotnet/issues/274/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-event-hubs-dotnet/issues/274/comments","events_url":"https://api.github.com/repos/Azure/azure-event-hubs-dotnet/issues/274/events","html_url":"https://github.com/Azure/azure-event-hubs-dotnet/issues/274","id":322951760,"number":274,"title":"Cannot access a disposed object. Object name: 'AmqpDataMessage'","user":{"login":"sflusov","id":11510074,"avatar_url":"https://avatars0.githubusercontent.com/u/11510074?v=4","gravatar_id":"","url":"https://api.github.com/users/sflusov","html_url":"https://github.com/sflusov","followers_url":"https://api.github.com/users/sflusov/followers","following_url":"https://api.github.com/users/sflusov/following{/other_user}","gists_url":"https://api.github.com/users/sflusov/gists{/gist_id}","starred_url":"https://api.github.com/users/sflusov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sflusov/subscriptions","organizations_url":"https://api.github.com/users/sflusov/orgs","repos_url":"https://api.github.com/users/sflusov/repos","events_url":"https://api.github.com/users/sflusov/events{/privacy}","received_events_url":"https://api.github.com/users/sflusov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-05-14T19:36:58Z","updated_at":"2018-05-15T17:27:34Z","closed_at":null,"author_association":"NONE","body":"## Actual Behavior\r\nDuring the day we are receiving not many exceptions from EventHub SDK. (System.ObjectDisposedException: Cannot access a disposed object. Object name: 'AmqpDataMessage') \r\n\r\nIt looks strange, because in our code there no places where we call Dispose for client or batch message.\r\n\r\nPlease have a look code which we use for sending messages:\r\n```\r\nprivate void ProcessEvents()\r\n{\r\n    while (!_isDisposed)\r\n    {\r\n        bool result = _autoResetEvent.WaitOne();\r\n        while (!_isDisposed)\r\n        {\r\n            var batch = (Microsoft.Azure.EventHubs.EventDataBatch)null;\r\n            lock (_queue)\r\n            {\r\n                while (!_isDisposed)\r\n                {\r\n                    var locEvent = (EventDataWrapper)null;\r\n                    if (!_queue.TryPeek(out locEvent))\r\n                        break;\r\n\r\n                    if (batch == null)\r\n                        batch = _sender.CreateBatch();\r\n\r\n                    var binEvent = Encoding.UTF8.GetBytes(locEvent.Data);\r\n                    var hubEvent = new Microsoft.Azure.EventHubs.EventData(binEvent);\r\n                    if (!batch.TryAdd(hubEvent))\r\n                        break;\r\n                }\r\n            }\r\n            \r\n            if (batch != null)\r\n\t      _sender.SendAsync(batch);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nBelow you could see stack trace received from EventHub SDK:\r\n```\r\nSystem.ObjectDisposedException: Cannot access a disposed object.\r\nObject name: 'AmqpDataMessage'.\r\nat Microsoft.Azure.Amqp.AmqpMessage.ThrowIfDisposed()\r\nat Microsoft.Azure.Amqp.SendingAmqpLink.BeginSendMessage(AmqpMessage message, ArraySegment`1 deliveryTag, ArraySegment`1 txnId, TimeSpan timeout, AsyncCallback callback, Object state)\r\nat Microsoft.Azure.Amqp.SendingAmqpLink.<>c__DisplayClass11_0.<SendMessageAsync>b__0(AsyncCallback c, Object s)\r\nat System.Threading.Tasks.TaskFactory`1.FromAsyncImpl(Func`3 beginMethod, Func`2 endFunction, Action`1 endAction, Object state, TaskCreationOptions creationOptions)\r\nat Microsoft.Azure.Amqp.SendingAmqpLink.SendMessageAsync(AmqpMessage message, ArraySegment`1 deliveryTag, ArraySegment`1 txnId, TimeSpan timeout)\r\nat Microsoft.Azure.EventHubs.Amqp.AmqpEventDataSender.<OnSendAsync>d__10.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat Microsoft.Azure.EventHubs.Amqp.AmqpEventDataSender.<OnSendAsync>d__10.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat Microsoft.Azure.EventHubs.PartitionSender.<SendAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat Microsoft.Azure.EventHubs.PartitionSender.<SendAsync>d__17.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat DC.Azure.Api.Services.PartitionEventSender.ProcessEvents() \r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat DC.Azure.Api.Controllers.v1.EventsController.<RegisterEvent>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\r\nat Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\nat Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)\r\nat Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\nat Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.<Invoke>d__11.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\nat System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\nat System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\nat NewRelic.Providers.Wrapper.AspNetCore.WrapPipelineMiddleware.<Invoke>d__3.MoveNext()\r\n```\r\n\r\n## Versions  \r\n- OS platform and version: Microsoft Windows Server 2012 R2 Datacenter (6.3.9600 Build 9600)\r\n- .NET Version: .NET Core 2.0\r\n- NuGet package version or commit ID: Microsoft.Azure.EventHubs (2.0.0)"},"comment":{"url":"https://api.github.com/repos/Azure/azure-event-hubs-dotnet/issues/comments/389248077","html_url":"https://github.com/Azure/azure-event-hubs-dotnet/issues/274#issuecomment-389248077","issue_url":"https://api.github.com/repos/Azure/azure-event-hubs-dotnet/issues/274","id":389248077,"user":{"login":"serkantkaraca","id":16924470,"avatar_url":"https://avatars1.githubusercontent.com/u/16924470?v=4","gravatar_id":"","url":"https://api.github.com/users/serkantkaraca","html_url":"https://github.com/serkantkaraca","followers_url":"https://api.github.com/users/serkantkaraca/followers","following_url":"https://api.github.com/users/serkantkaraca/following{/other_user}","gists_url":"https://api.github.com/users/serkantkaraca/gists{/gist_id}","starred_url":"https://api.github.com/users/serkantkaraca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serkantkaraca/subscriptions","organizations_url":"https://api.github.com/users/serkantkaraca/orgs","repos_url":"https://api.github.com/users/serkantkaraca/repos","events_url":"https://api.github.com/users/serkantkaraca/events{/privacy}","received_events_url":"https://api.github.com/users/serkantkaraca/received_events","type":"User","site_admin":false},"created_at":"2018-05-15T17:27:34Z","updated_at":"2018-05-15T17:27:34Z","author_association":"MEMBER","body":"I have prepared a fix already. This will be part of next client release. https://github.com/Azure/azure-event-hubs-dotnet/pull/275\r\n\r\n"}}
{"actor":{"display_login":"serkantkaraca"}}