{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Caching/issues/361","repository_url":"https://api.github.com/repos/aspnet/Caching","labels_url":"https://api.github.com/repos/aspnet/Caching/issues/361/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Caching/issues/361/comments","events_url":"https://api.github.com/repos/aspnet/Caching/issues/361/events","html_url":"https://github.com/aspnet/Caching/issues/361","id":275482502,"number":361,"title":"MemoryCache generic TryGetValue throws InvalidCastException when trying to get value","user":{"login":"tstanitz","id":8086966,"avatar_url":"https://avatars3.githubusercontent.com/u/8086966?v=4","gravatar_id":"","url":"https://api.github.com/users/tstanitz","html_url":"https://github.com/tstanitz","followers_url":"https://api.github.com/users/tstanitz/followers","following_url":"https://api.github.com/users/tstanitz/following{/other_user}","gists_url":"https://api.github.com/users/tstanitz/gists{/gist_id}","starred_url":"https://api.github.com/users/tstanitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tstanitz/subscriptions","organizations_url":"https://api.github.com/users/tstanitz/orgs","repos_url":"https://api.github.com/users/tstanitz/repos","events_url":"https://api.github.com/users/tstanitz/events{/privacy}","received_events_url":"https://api.github.com/users/tstanitz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-11-20T20:09:27Z","updated_at":"2017-11-20T20:57:54Z","closed_at":null,"author_association":"NONE","body":"Hello,\r\n\r\nI have found that InvalidCastException coming from the generic TryGetValue extension method when the type of the value related to the key is not compatible with the provided generic type.\r\n\r\nTo reproduce:\r\n1. Add a value to the cache for some key\r\n2. Call the TryGetValue generic method with a key and a non-compatible out parameter\r\n3. InvalidCastException is thrown\r\n\r\nIt should not throw any exception, but return false and set the out parameter to default.\r\n\r\nThe exception comes from the explicit casting:\r\nhttps://github.com/aspnet/Caching/blob/23a89b78fedea611d74e3a754bc4843115013ae1/src/Microsoft.Extensions.Caching.Abstractions/MemoryCacheExtensions.cs\r\n\r\nThanks"},"comment":{"url":"https://api.github.com/repos/aspnet/Caching/issues/comments/345829620","html_url":"https://github.com/aspnet/Caching/issues/361#issuecomment-345829620","issue_url":"https://api.github.com/repos/aspnet/Caching/issues/361","id":345829620,"user":{"login":"JunTaoLuo","id":2030323,"avatar_url":"https://avatars1.githubusercontent.com/u/2030323?v=4","gravatar_id":"","url":"https://api.github.com/users/JunTaoLuo","html_url":"https://github.com/JunTaoLuo","followers_url":"https://api.github.com/users/JunTaoLuo/followers","following_url":"https://api.github.com/users/JunTaoLuo/following{/other_user}","gists_url":"https://api.github.com/users/JunTaoLuo/gists{/gist_id}","starred_url":"https://api.github.com/users/JunTaoLuo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JunTaoLuo/subscriptions","organizations_url":"https://api.github.com/users/JunTaoLuo/orgs","repos_url":"https://api.github.com/users/JunTaoLuo/repos","events_url":"https://api.github.com/users/JunTaoLuo/events{/privacy}","received_events_url":"https://api.github.com/users/JunTaoLuo/received_events","type":"User","site_admin":false},"created_at":"2017-11-20T20:57:54Z","updated_at":"2017-11-20T20:57:54Z","author_association":"CONTRIBUTOR","body":"I think we should still follow the convention of other APIs for Try* where if it's not successful, it should return false instead of throwing."}}
{"actor":{"display_login":"JunTaoLuo"}}