Closed RefractedPaladin closed 10 years ago
Have you stepped through the code and inspected the values right before the exception? I'd be interested to see which argument it thinks is null. I have a feeling it might be the Models.Employee
instance. Let me know what you find.
I did and it didn't seem so. I'll double check though. The Values I mentioned above are right at that point where it throws Exception.
The objectClass
parameter of the PopulateClass()
method that this is occuring in is set to Models.Employee
...
I'm looking though, maybe I'm not instantiating it correctly...
Nope, Employee instance is definetly there. I posted this same question on SO, here --> http://stackoverflow.com/questions/21003185/argumentexception-on-propertyinfo-setvalue-in-net-compact
Crowd sourcing, as it were, as I'm sure you are busy and who knows if I'm doing something silly again.
Not sure if this matters or not but when I step through the code and inspect the values I notice that, in SqlMapper.cs on line 99, the actualType == Int32
and the columnType==Int64
while the value
it's evaluating is 1
. Not sure that makes any difference since you have a actualType.Equals(typeof(int))
but figured I'd mention it.
That's actually pretty interesting, but will work fine. It should be caught by the last condition in the first if statement branch: https://github.com/ryankirkman/DapperLite/blob/master/DapperLite.NETCF35/SqlMapper.cs#L86
e.g. actualType == typeof(int)
int
is a synonym for Int32
in C#, so it will directly assign 1
to the Int64
column. I think this is fine, as any Int32
value will easily fit in an Int64
. If it was going the other way, e.g. assigning an Int64
to an Int32
we'd have problems.
That's what I figured as well but thought I'd check. Unfortunately I am running out of things to even try at this point. Bummer as I was really looking forward to using this library as well as it's big brother.
Thanks for the help so far.
No worries mate. I'll tell you what - I'll load up your class when I get a chance and try to reproduce the problems you're experiencing.
The other thing your could try is changing your model such that Id
is an Int64
rather than int
. Let me know how that goes
Hey Thanks! Whatever you can spare is very appreciated!
So, changing it to Int64 in my model worked.... :-)
Huh, that's interesting. Turns out you can't directly assign an Int32
to an Int64
via PropertyInfo.SetValue
. Now we know :)
Mind if I answer the question on StackOverflow?
No, go ahead. I'll vote it up and check it the answer. Will you make any chanegs to SqlMapper.cs to account for this? I wonder why it thinks it's Int64, must be a SQLite thing huh?
Yeah, good question. I will make a change, but I have to think what the best way to go about this is. I think it might be dropping those last two conditions on the first part of the if statement. That will fix a few bugs actually, and I'll do that now.
Fixed: 43f5588ec15c54c8dea40fec15f3a0b5a9a73f07!
Try pulling the latest changes and let me know if you have any more problems :)
@RefractedPaladin Actually, just landed a change to the if statement that should keep it super fast for simple value type Type comparisons: d76db77f78a8023960097f8da09a722892950dee
Based on the info in this blog post: http://blogs.msdn.com/b/csharpfaq/archive/2004/03/29/when-should-i-use-and-when-should-i-use-equals.aspx
Nice! That makes sense. I'm up and running on it now so I'll let you know how it goes.
Thanks for the help!
On Fri, Jan 17, 2014 at 2:22 PM, Ryan Kirkman notifications@github.comwrote:
Based on the info in this blog post: http://blogs.msdn.com/b/csharpfaq/archive/2004/03/29/when-should-i-use-and-when-should-i-use-equals.aspx
— Reply to this email directly or view it on GitHubhttps://github.com/ryankirkman/DapperLite/issues/3#issuecomment-32643001 .
Specifically line 100 in SqlMapper.cs is throwing that.
pi.SetValue(objectClass, value, null);
Values for those parameters are
Models.Employee
&1
It should be trying to assign the
Id
aspi
is anInt32
from the ColumnId