{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/orleans/issues/3212","repository_url":"https://api.github.com/repos/dotnet/orleans","labels_url":"https://api.github.com/repos/dotnet/orleans/issues/3212/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/orleans/issues/3212/comments","events_url":"https://api.github.com/repos/dotnet/orleans/issues/3212/events","html_url":"https://github.com/dotnet/orleans/issues/3212","id":242007568,"number":3212,"title":"NullReferenceException for multiple implicit stream subscriptions","user":{"login":"charleszipp","id":4292559,"avatar_url":"https://avatars3.githubusercontent.com/u/4292559?v=4","gravatar_id":"","url":"https://api.github.com/users/charleszipp","html_url":"https://github.com/charleszipp","followers_url":"https://api.github.com/users/charleszipp/followers","following_url":"https://api.github.com/users/charleszipp/following{/other_user}","gists_url":"https://api.github.com/users/charleszipp/gists{/gist_id}","starred_url":"https://api.github.com/users/charleszipp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charleszipp/subscriptions","organizations_url":"https://api.github.com/users/charleszipp/orgs","repos_url":"https://api.github.com/users/charleszipp/repos","events_url":"https://api.github.com/users/charleszipp/events{/privacy}","received_events_url":"https://api.github.com/users/charleszipp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"jason-bragg","id":10675494,"avatar_url":"https://avatars2.githubusercontent.com/u/10675494?v=4","gravatar_id":"","url":"https://api.github.com/users/jason-bragg","html_url":"https://github.com/jason-bragg","followers_url":"https://api.github.com/users/jason-bragg/followers","following_url":"https://api.github.com/users/jason-bragg/following{/other_user}","gists_url":"https://api.github.com/users/jason-bragg/gists{/gist_id}","starred_url":"https://api.github.com/users/jason-bragg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jason-bragg/subscriptions","organizations_url":"https://api.github.com/users/jason-bragg/orgs","repos_url":"https://api.github.com/users/jason-bragg/repos","events_url":"https://api.github.com/users/jason-bragg/events{/privacy}","received_events_url":"https://api.github.com/users/jason-bragg/received_events","type":"User","site_admin":false},"assignees":[{"login":"jason-bragg","id":10675494,"avatar_url":"https://avatars2.githubusercontent.com/u/10675494?v=4","gravatar_id":"","url":"https://api.github.com/users/jason-bragg","html_url":"https://github.com/jason-bragg","followers_url":"https://api.github.com/users/jason-bragg/followers","following_url":"https://api.github.com/users/jason-bragg/following{/other_user}","gists_url":"https://api.github.com/users/jason-bragg/gists{/gist_id}","starred_url":"https://api.github.com/users/jason-bragg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jason-bragg/subscriptions","organizations_url":"https://api.github.com/users/jason-bragg/orgs","repos_url":"https://api.github.com/users/jason-bragg/repos","events_url":"https://api.github.com/users/jason-bragg/events{/privacy}","received_events_url":"https://api.github.com/users/jason-bragg/received_events","type":"User","site_admin":false},{"login":"xiazen","id":20803801,"avatar_url":"https://avatars3.githubusercontent.com/u/20803801?v=4","gravatar_id":"","url":"https://api.github.com/users/xiazen","html_url":"https://github.com/xiazen","followers_url":"https://api.github.com/users/xiazen/followers","following_url":"https://api.github.com/users/xiazen/following{/other_user}","gists_url":"https://api.github.com/users/xiazen/gists{/gist_id}","starred_url":"https://api.github.com/users/xiazen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiazen/subscriptions","organizations_url":"https://api.github.com/users/xiazen/orgs","repos_url":"https://api.github.com/users/xiazen/repos","events_url":"https://api.github.com/users/xiazen/events{/privacy}","received_events_url":"https://api.github.com/users/xiazen/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/dotnet/orleans/milestones/13","html_url":"https://github.com/dotnet/orleans/milestone/13","labels_url":"https://api.github.com/repos/dotnet/orleans/milestones/13/labels","id":1873066,"number":13,"title":"2.0.0","description":"Key target is compatibility with .NET Core.","creator":{"login":"sergeybykov","id":8248806,"avatar_url":"https://avatars1.githubusercontent.com/u/8248806?v=4","gravatar_id":"","url":"https://api.github.com/users/sergeybykov","html_url":"https://github.com/sergeybykov","followers_url":"https://api.github.com/users/sergeybykov/followers","following_url":"https://api.github.com/users/sergeybykov/following{/other_user}","gists_url":"https://api.github.com/users/sergeybykov/gists{/gist_id}","starred_url":"https://api.github.com/users/sergeybykov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergeybykov/subscriptions","organizations_url":"https://api.github.com/users/sergeybykov/orgs","repos_url":"https://api.github.com/users/sergeybykov/repos","events_url":"https://api.github.com/users/sergeybykov/events{/privacy}","received_events_url":"https://api.github.com/users/sergeybykov/received_events","type":"User","site_admin":false},"open_issues":65,"closed_issues":27,"state":"open","created_at":"2016-07-08T21:14:40Z","updated_at":"2017-08-14T20:33:27Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2017-07-11T10:58:28Z","updated_at":"2017-08-14T20:36:55Z","closed_at":null,"body":"I am trying to create an actor that subscribes to multiple streams on the same stream namespace. This is done to facilitate both fire-and-forget style calls but, more importantly, to remove the temporal dependency between this actor and other actors in different solutions.\r\n\r\nWhen i produce the CommandDispatched event, the actor is activated as expected. However, i want to also ensure a subscription is setup for other events (CommandStarted, CommandCompleted, etc). When it hits the second subscription for CommandStarted, a NullReferenceException is thrown.\r\n\r\nAt the time the exception is thrown, there are not actually any CommandStarted events on the stream. However, i need some way to subscribe to this stream before its events are produced. Do i need to do an explicit subscription here? Possibly from the CommandDispatched handler?\r\n\r\n```csharp\r\n[ImplicitStreamSubscription(\"Routes.Activities\")]\r\npublic class ActivityMonitor : JournaledGrain<ActivityState, IEvent>, IActivityMonitor\r\n{\r\n\tprotected Task OnObserveCommandDispatched(CommandDispatched @event, StreamSequenceToken token = null)\r\n    {\r\n        //handle event\r\n        return Task.CompletedTask;\r\n    }\r\n\r\n    protected Task OnObserveCommandStarted(CommandStarted @event, StreamSequenceToken token = null)\r\n    {\r\n        //handle event\r\n        return Task.CompletedTask;\r\n    }\r\n\r\n    public override async Task OnActivateAsync()\r\n    {\r\n        await GetStreamProvider(\"activities\").GetStream<CommandDispatched>(this.GetPrimaryKey(), \"Routes.Activities\").SubscribeAsync(OnObserveCommandDispatched);\r\n        //this throws exception object null reference exception\r\n        await GetStreamProvider(\"activities\").GetStream<CommandStarted>(this.GetPrimaryKey(), \"Routes.Activities\").SubscribeAsync(OnObserveCommandStarted);\r\n    }\r\n}\r\n\r\npublic class Program\r\n{\r\n\tprivate static IClientFactory _clients = new ServiceFabricClusterClientFactory();\r\n\tprivate static void Main(string[] args)\r\n\t{\r\n\t\tvar client = _clients.Get<IActivityMonitor>().Result;\r\n\t\tvar command = new CreateEngagementArgs(id, \"Test 123\", firmGuid);\r\n        var @event = new EngagementCreated(id, \"Test 123\", firmGuid);\r\n\r\n        client.GetStreamProvider(\"activities\").GetStream<CommandDispatched>(activityId, \"Routes.Activities\").OnNextAsync(\r\n            new CommandDispatched(activityId, \"Routes.Activities\", Newtonsoft.Json.JsonConvert.SerializeObject(command), DateTime.UtcNow)\r\n            ).Wait();\r\n\r\n        //todo: produce CommandStarted...\r\n\t}\r\n}\r\n```\r\n\r\n```\r\nAudit.Sagas.Actors.exe Error: 0 : [2017-07-11 10:44:17.791 GMT    22\tERROR  \t100513\tCatalog\t127.0.0.1:30023]\t!!!!!!!!!! Error calling grain's OnActivateAsync() method - Grain type = Audit.Sagas.Actors.ActivityMonitor Activation = [Activation: S127.0.0.1:30023:237465823*grn/282D34D6/8d50069f@14f196be #GrainType=Audit.Sagas.Actors.ActivityMonitor Placement=RandomPlacement State=Activating]\t\r\nExc level 0: System.NullReferenceException: Object reference not set to an instance of an object.\r\n   at Orleans.Streams.AsyncObservableExtensions.SubscribeAsync[T](IAsyncObservable`1 obs, Func`3 onNextAsync, Func`2 onErrorAsync, Func`1 onCompletedAsync)\r\n   at Orleans.Streams.AsyncObservableExtensions.SubscribeAsync[T](IAsyncObservable`1 obs, Func`3 onNextAsync)\r\n   at Audit.Sagas.Actors.ActivityMonitor.<OnActivateAsync>d__7.MoveNext() in C:\\Code\\Test\\Audit\\Audit\\Audit.Sagas.Actors\\ActivityMonitor.cs:line 370\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Orleans.Runtime.Catalog.<CallGrainActivate>d__87.MoveNext()\r\nAudit.Sagas.Actors.exe Warning: 0 : [2017-07-11 10:44:17.796 GMT    25\tWARNING\t100534\tCatalog\t127.0.0.1:30023]\tFailed to InvokeActivate for [Activation: S127.0.0.1:30023:237465823*grn/282D34D6/8d50069f@14f196be #GrainType=Audit.Sagas.Actors.ActivityMonitor Placement=RandomPlacement State=Invalid].\t\r\nExc level 0: System.NullReferenceException: Object reference not set to an instance of an object.\r\n   at Orleans.Streams.AsyncObservableExtensions.SubscribeAsync[T](IAsyncObservable`1 obs, Func`3 onNextAsync, Func`2 onErrorAsync, Func`1 onCompletedAsync)\r\n   at Orleans.Streams.AsyncObservableExtensions.SubscribeAsync[T](IAsyncObservable`1 obs, Func`3 onNextAsync)\r\n   at Audit.Sagas.Actors.ActivityMonitor.<OnActivateAsync>d__7.MoveNext() in C:\\Code\\Test\\Audit\\Audit\\Audit.Sagas.Actors\\ActivityMonitor.cs:line 370\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Orleans.Runtime.Catalog.<CallGrainActivate>d__87.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Orleans.Runtime.Scheduler.SchedulerExtensions.<>c__DisplayClass1_0.<<QueueTask>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Orleans.Runtime.Catalog.<InitActivation>d__66.MoveNext()\r\n```"},"comment":{"url":"https://api.github.com/repos/dotnet/orleans/issues/comments/322302366","html_url":"https://github.com/dotnet/orleans/issues/3212#issuecomment-322302366","issue_url":"https://api.github.com/repos/dotnet/orleans/issues/3212","id":322302366,"user":{"login":"xiazen","id":20803801,"avatar_url":"https://avatars3.githubusercontent.com/u/20803801?v=4","gravatar_id":"","url":"https://api.github.com/users/xiazen","html_url":"https://github.com/xiazen","followers_url":"https://api.github.com/users/xiazen/followers","following_url":"https://api.github.com/users/xiazen/following{/other_user}","gists_url":"https://api.github.com/users/xiazen/gists{/gist_id}","starred_url":"https://api.github.com/users/xiazen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiazen/subscriptions","organizations_url":"https://api.github.com/users/xiazen/orgs","repos_url":"https://api.github.com/users/xiazen/repos","events_url":"https://api.github.com/users/xiazen/events{/privacy}","received_events_url":"https://api.github.com/users/xiazen/received_events","type":"User","site_admin":false},"created_at":"2017-08-14T20:36:55Z","updated_at":"2017-08-14T20:36:55Z","body":"Submitted a fix in #3301 "}}
{"actor":{"display_login":"xiazen"}}