{"action":"created","issue":{"url":"https://api.github.com/repos/StackExchange/dapper-dot-net/issues/488","repository_url":"https://api.github.com/repos/StackExchange/dapper-dot-net","labels_url":"https://api.github.com/repos/StackExchange/dapper-dot-net/issues/488/labels{/name}","comments_url":"https://api.github.com/repos/StackExchange/dapper-dot-net/issues/488/comments","events_url":"https://api.github.com/repos/StackExchange/dapper-dot-net/issues/488/events","html_url":"https://github.com/StackExchange/dapper-dot-net/issues/488","id":143829804,"number":488,"title":"Dapper throws exception second time you run a query if different results schema","user":{"login":"mgimeno","id":2883676,"avatar_url":"https://avatars.githubusercontent.com/u/2883676?v=3","gravatar_id":"","url":"https://api.github.com/users/mgimeno","html_url":"https://github.com/mgimeno","followers_url":"https://api.github.com/users/mgimeno/followers","following_url":"https://api.github.com/users/mgimeno/following{/other_user}","gists_url":"https://api.github.com/users/mgimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/mgimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgimeno/subscriptions","organizations_url":"https://api.github.com/users/mgimeno/orgs","repos_url":"https://api.github.com/users/mgimeno/repos","events_url":"https://api.github.com/users/mgimeno/events{/privacy}","received_events_url":"https://api.github.com/users/mgimeno/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2016-03-27T17:19:09Z","updated_at":"2016-03-28T22:18:17Z","closed_at":null,"body":"I just raised the same issue on Stackoverflow:\r\nhttp://stackoverflow.com/questions/36250047/dapper-throws-exception-second-time-you-run-a-query-if-different-results-schema\r\n\r\nI'm using Dapper, Sqlite on c# coreclr.\r\n\r\n```C#\r\npublic async Task<UserPoco> GetFromEmail(string email)\r\n{\r\n    email = email.ToLower();\r\n\r\n    using (var connection = new SqliteConnection(_configSettings.ConnectionString))\r\n    {\r\n        connection.Open();\r\n        var query = $\"SELECT * FROM users WHERE EmailAddress = '{email}';\";\r\n        var result = await connection.QueryAsync<UserPoco>(query);\r\n        return result.FirstOrDefault();\r\n    }\r\n}\r\n```\r\n\r\nThat simple method throws an exception if at some point the SQL query find no results and next time it runs it does find results. It throws: Unable to cast object of type 'System.Int64' to type 'System.Int32'. Error parsing column 0 (UserId=86 - Int64)\r\n\r\nI'm pretty sure it's not related to the Datatypes. The UserPoco has a long UserId property and the DB table users has a UserId of type INTEGER which is the recommended one to store bigint (long). Moreover, for example if the method always finds data it will work like a charm. I do think is related to the fact that Dapper caches the result schema of every query it runs and throws an exception when this schema changes for the same query as they point out on: https://github.com/janjosephlim/dapper-dot-net/issues/124\r\n\r\nWhat I don't understand is how come I can't find more info about this or more people is complaining about such a common scenario: I'm just running a very simple query multiple times which can bring back or not results.\r\n\r\nWhat am I missing?"},"comment":{"url":"https://api.github.com/repos/StackExchange/dapper-dot-net/issues/comments/202602044","html_url":"https://github.com/StackExchange/dapper-dot-net/issues/488#issuecomment-202602044","issue_url":"https://api.github.com/repos/StackExchange/dapper-dot-net/issues/488","id":202602044,"user":{"login":"mgravell","id":17328,"avatar_url":"https://avatars.githubusercontent.com/u/17328?v=3","gravatar_id":"","url":"https://api.github.com/users/mgravell","html_url":"https://github.com/mgravell","followers_url":"https://api.github.com/users/mgravell/followers","following_url":"https://api.github.com/users/mgravell/following{/other_user}","gists_url":"https://api.github.com/users/mgravell/gists{/gist_id}","starred_url":"https://api.github.com/users/mgravell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgravell/subscriptions","organizations_url":"https://api.github.com/users/mgravell/orgs","repos_url":"https://api.github.com/users/mgravell/repos","events_url":"https://api.github.com/users/mgravell/events{/privacy}","received_events_url":"https://api.github.com/users/mgravell/received_events","type":"User","site_admin":false},"created_at":"2016-03-28T22:18:16Z","updated_at":"2016-03-28T22:18:16Z","body":"Fair enough. It is awkward and vexing that rc2 has been delayed - it is\ncreating much gnashing of teeth when there are things that are known to be\nfixed but we can't get the bits easily :(\nOn 28 Mar 2016 10:05 p.m., \"Marcos\" <notifications@github.com> wrote:\n\n> I tried updating:\n> \"Microsoft.Data.Sqlite\": \"1.0.0-rc2-15948\"\n> Doing that I can use parameters on my queries which I couldn't before,\n> however I still need to use:\n> \"Dapper\": \"1.50.0-beta4\" to avoid getting \"The CommandBehavior\n> 'SingleResult, SequentialAccess' is invalid.\" with a newer versions.\n> With that setup, I still get the error stated on my first post.\n>\n> The only newer version of Microsoft.Data.Sqlite I can use is\n> \"1.0.0-rc2-16099\" as newer than that are not compatible with dnxcore50 and\n> that version has a dependency on \"System.Runtime\": \"4.1.0.0\", so I updated\n> all my projects in the solution with \"System.Runtime\": \"4.1.0-rc2-23819\"\n> which also at some point made me update \"Microsoft.CSharp\" to\n> \"4.0.1-rc2-23819\".\n>\n> Now my project is building ok but I'm getting the following runtime error\n> when I start the app:\n> System.IO.FileLoadException\n> Could not load file or assembly 'System.Runtime, Version=4.1.0.0,\n> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its\n> dependencies. The located assembly's manifest definition does not match the\n> assembly reference. (Exception from HRESULT: 0x80131040)\n> .NET Framework CoreClr version 4.0.21.0 | DNX x86 version 1.0.0-rc1-16231\n> | Microsoft.AspNet.Hosting version 1.0.0-rc1-15988 | Windows 10.0 |\n>\n> Note: I also did dnvm update -u so when I do dnvm list I get:\n>\n>    - 1.0.0-rc2-20221 clr x86 C:\\Users\\mgimeno.dnx\\runtimes default\n>\n> I just got stuck with that error. Anyway I'm not very positive that even\n> fixing that error, that new version of sqlite would make any difference\n> regarding my original issue.\n>\n> So, after spending way too much time in trying to make work such a simple\n> scenario I've decided to move to another solution (not sure which yet) and\n> maybe come back and try Dapper+Sqlite when new versions are released.\n>\n> @NickCraver <https://github.com/NickCraver> , @mgravell\n> <https://github.com/mgravell> Thank you anyway for your help,\n>\n> —\n> You are receiving this because you were mentioned.\n> Reply to this email directly or view it on GitHub\n> <https://github.com/StackExchange/dapper-dot-net/issues/488#issuecomment-202580895>\n>\n"}}