So I we upgraded to .NET 4.5 a couple days ago and we ran into some issues. All of the sudden I received an ArguementException , "Incorrect number of arguments for constructor". This is code that obviously worked before. I got it on linq to entity queries
that had an anonymous type with more than two properties. What is really strange is that it appears to have something to with order of these properties in the query for example, I get an error with this query.
void Main()
{
var query = from t in tasks
join tn in task_note on t.task_id equals tn.task_id
select new { t, note = tn, Bogus = "", };
query.ToList();
}
So I started playing around to see if I could see a pattern in this to find out what would work. If I remove the "Bogus" property it works fine.
void Main()
{
var query = from t in tasks
join tn in task_note on t.task_id equals tn.task_id
select new { t, note = tn };
query.ToList();
}
So two properties work just fine. How about another way to use 3? How about this?
void Main()
{
var query = from t in tasks
join tn in task_note on t.task_id equals tn.task_id
select new { t, Bogus = "", note = tn, };
query.ToList();
}
So if I move the entity aware property to the end of the class declaration it actually works? Can you say #$@#%%^? I suspect the index of the properties is determined by what classes are used in the anonymous type declaration. So they must have left something
out when a simple type is returned in the index at the end of the type declaration. Hopefully this helps someone else out.
This in-place upgrade is a real nightmare.
UPDATE:
If you want to reproduce or play with I have this LINQPad
file that has the repro. It reference a solution in a zip file at this
location.
bkotvis
Member
396 Points
83 Posts
.NET 4.5 (ArgumentException: Incorrect number of arguments for constructor)
Dec 09, 2012 05:32 PM|LINK
So I we upgraded to .NET 4.5 a couple days ago and we ran into some issues. All of the sudden I received an ArguementException , "Incorrect number of arguments for constructor". This is code that obviously worked before. I got it on linq to entity queries that had an anonymous type with more than two properties. What is really strange is that it appears to have something to with order of these properties in the query for example, I get an error with this query.
void Main() { var query = from t in tasks join tn in task_note on t.task_id equals tn.task_id select new { t, note = tn, Bogus = "", }; query.ToList(); }So I started playing around to see if I could see a pattern in this to find out what would work. If I remove the "Bogus" property it works fine.
void Main() { var query = from t in tasks join tn in task_note on t.task_id equals tn.task_id select new { t, note = tn }; query.ToList(); }So two properties work just fine. How about another way to use 3? How about this?
void Main() { var query = from t in tasks join tn in task_note on t.task_id equals tn.task_id select new { t, Bogus = "", note = tn, }; query.ToList(); }So if I move the entity aware property to the end of the class declaration it actually works? Can you say #$@#%%^? I suspect the index of the properties is determined by what classes are used in the anonymous type declaration. So they must have left something out when a simple type is returned in the index at the end of the type declaration. Hopefully this helps someone else out.
This in-place upgrade is a real nightmare.
UPDATE:
If you want to reproduce or play with I have this LINQPad file that has the repro. It reference a solution in a zip file at this location.
moozzyk
Member
10 Points
5 Posts
Re: .NET 4.5 (ArgumentException: Incorrect number of arguments for constructor)
Dec 11, 2012 04:35 PM|LINK
I was able to repro this and followed up internally. We are considering addressing this in one of the future updates.
Thanks for reporting this and providing the repro,
Pawel
bkotvis
Member
396 Points
83 Posts
Re: .NET 4.5 (ArgumentException: Incorrect number of arguments for constructor)
Dec 11, 2012 06:19 PM|LINK
That's great! I hope you can get it fixed soon.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: .NET 4.5 (ArgumentException: Incorrect number of arguments for constructor)
Dec 15, 2012 01:07 AM|LINK
Hi,
sorry for late reply.
You can submit your nice idea at:
http://connect.microsoft.com
Reguards!