{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1009","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1009/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1009/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1009/events","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1009","id":123460954,"number":1009,"title":"SubstitutionMapperStrategy NullReferenceException","user":{"login":"antoinebj","id":6056675,"avatar_url":"https://avatars.githubusercontent.com/u/6056675?v=3","gravatar_id":"","url":"https://api.github.com/users/antoinebj","html_url":"https://github.com/antoinebj","followers_url":"https://api.github.com/users/antoinebj/followers","following_url":"https://api.github.com/users/antoinebj/following{/other_user}","gists_url":"https://api.github.com/users/antoinebj/gists{/gist_id}","starred_url":"https://api.github.com/users/antoinebj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoinebj/subscriptions","organizations_url":"https://api.github.com/users/antoinebj/orgs","repos_url":"https://api.github.com/users/antoinebj/repos","events_url":"https://api.github.com/users/antoinebj/events{/privacy}","received_events_url":"https://api.github.com/users/antoinebj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-22T11:08:53Z","updated_at":"2015-12-22T12:26:52Z","closed_at":null,"body":"When using `CreateMap<,>.Substitute()`, if the delegate returns null, the call to `newSource.GetType()` in `SubstutitionMapperStrategy.Map()` generates a `NullReferenceException`.\r\n\r\nhttps://github.com/AutoMapper/AutoMapper/blob/develop/src/AutoMapper/Mappers/TypeMapObjectMapperRegistry.cs#L39\r\n\r\nAt first glance this looks like an oversight and therefore a bug, but perhaps it is intentional?\r\n\r\nI stumbled upon this while using such code:\r\n```csharp\r\nmap.Substitute(src => src != null ? src.SomeField : null)\r\n```\r\nI wrote this code because the substitution delegate is called even though the source is null. Is that also intended behavior?\r\n\r\nAnd by the way there is a typo in the class name: `SubstutitionMapperStrategy`"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/166605901","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1009#issuecomment-166605901","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1009","id":166605901,"user":{"login":"lbargaoanu","id":4517428,"avatar_url":"https://avatars.githubusercontent.com/u/4517428?v=3","gravatar_id":"","url":"https://api.github.com/users/lbargaoanu","html_url":"https://github.com/lbargaoanu","followers_url":"https://api.github.com/users/lbargaoanu/followers","following_url":"https://api.github.com/users/lbargaoanu/following{/other_user}","gists_url":"https://api.github.com/users/lbargaoanu/gists{/gist_id}","starred_url":"https://api.github.com/users/lbargaoanu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbargaoanu/subscriptions","organizations_url":"https://api.github.com/users/lbargaoanu/orgs","repos_url":"https://api.github.com/users/lbargaoanu/repos","events_url":"https://api.github.com/users/lbargaoanu/events{/privacy}","received_events_url":"https://api.github.com/users/lbargaoanu/received_events","type":"User","site_admin":false},"created_at":"2015-12-22T12:26:52Z","updated_at":"2015-12-22T12:26:52Z","body":"Is there any reason you're not using MapFrom or ResolveUsing?"}}