Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidProgramException on prerelease when first field is a non-numeric type #1279

Closed
jnm2 opened this issue Jun 12, 2019 · 3 comments · Fixed by #1280
Closed

InvalidProgramException on prerelease when first field is a non-numeric type #1279

jnm2 opened this issue Jun 12, 2019 · 3 comments · Fixed by #1280

Comments

@jnm2
Copy link
Contributor

jnm2 commented Jun 12, 2019

@mgravell It seems very likely that this one is on me via #1242. I'll get a full repro and fix it ASAP.

https://www.myget.org/feed/stackoverflow/package/nuget/Dapper/1.60.14 works fine with (int, string, string, DateTime?, DateTime?, DateTime?, decimal?, DateTime?, string, int?, DateTime?, DateTime?, int?) rows.

With (string, byte[], byte[]), it breaks:

System.InvalidProgramException:
Common Language Runtime detected an invalid program.
at Deserialize669fc2c6-0ab9-4b1c-ae66-ee2bfbcc0010(IDataReader )
at Dapper.SqlMapper.d__34`1.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.Async.cs:line 500

@jnm2 jnm2 changed the title InvalidProgramException using InvalidProgramException on prerelease when getting (string, byte[], byte[]) rows Jun 12, 2019
@jnm2
Copy link
Contributor Author

jnm2 commented Jun 12, 2019

ValueTuple<byte[]> and ValueTuple<string> both repro this, so I'm likely treating a reference type like a value type somewhere.

Oddly, the existing (int, string) tests don't trigger this bug. It appears to affect the first but not the second tuple element.

@jnm2
Copy link
Contributor Author

jnm2 commented Jun 13, 2019

Think I spotted it. In the main path, local 0 holds the current reader field index for retrieval on exceptions for diagnostic purposes. In the ValueTuple path, this local does not exist, so the following code writes into whatever local was created, which may be a string or byte[] local, created later on in the IL generation:

https://github.com/StackExchange/Dapper/blob/fcd8a70279fbe19e2aa0dbc81f7625a0ddae5e2f/Dapper/SqlMapper.cs#L3411-L3417

@jnm2
Copy link
Contributor Author

jnm2 commented Jun 13, 2019

That was it. PR incoming.

@jnm2 jnm2 changed the title InvalidProgramException on prerelease when getting (string, byte[], byte[]) rows InvalidProgramException on prerelease when first field is a non-numeric type Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant