I have simplified this even further; with all the interface cruft out
of the way, it seems like the problem is that even the simplest "join"
is going to cause a JIT error? This sounds like a bug to me, but I'm
happy to be told it's my fault :).

The code that causes the problem is below, reduced to about its bare
minimum. git://github.com/bschuth/MT-JIT-Problem.git has been updated
as well...

But the problem is really simple: I have two collections of objects
(sessions and scores) connected by an integer key in a one-to-many
relationship, where score.OwnerID equal session.SessionID. This linq
fails:

from s in sessions
join score in scores
on s.SessionID equals score.OwnerID
select score.Name;

Are joins just not possible here? What to do? Thanks.

==== Source: PROBLEMLINQ.CS STARTS
using System;
using System.Linq;
using System.Collections.Generic;

namespace JIT20110908
{
public class ProblemLinq
{
public IList<string> Execute ()
{
List<ActualScore> scores = new List<ActualScore> ();
ActualScore score1 = new ActualScore () {
Name = "ACTIVITIES",
OwnerID = 666
};
scores.Add (score1);

List<MySession> sessions = new List<MySession> ();
MySession mysession = new MySession () {
SessionID = 666,
};
sessions.Add (mysession);

var summaryVar = from s in sessions
                             join score in scores
                             on s.SessionID equals score.OwnerID
                             select score.Name;

List<string> summaryRows = summaryVar.ToList();
return summaryRows;
}
}

public class MySession
{
public int SessionID { get; set; }
}

public class ActualScore
{
public int OwnerID { get; set; }
public string Name { get; set; }
}
}

On Fri, Sep 9, 2011 at 9:07 AM, Brian Schuth <[email protected]> wrote:
>
> Thanks, this confirms my vague sense that the problem came from something the 
> LINQ depends on that is not generated during compilation. This specific fix 
> doesn't work, since the type involved isn't quite the same. I'm relatively 
> new to the guts of LINQ, so I think I need some help parsing exactly what the 
> error is.
> The stack trace says it is attempting to compile this method:
> System.Linq.Enumerable:<ToLookup`2>m__18<JIT20110908.ActualScore, 
> int>(JIT20110908.ActualScore)
> I tried just substituting ActualScore as the type in your fix, but that 
> doesn't seem to do it either.
> The exception occurs inside the method:
> at System.Linq.Enumerable.ToLookup[ActualScore,Int32,ActualScore] 
> (IEnumerable`1 source, System.Func`2 keySelector, System.Func`2 
> elementSelector, IEqualityComparer`1 comparer) [0x00079] in 
> /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2915
> I've read the docs on Enumerable.ToLookup, and maybe I just need more coffee, 
> but I'm not quite getting what this may be trying to do at the mysterious 
> line 2915 that is causing a crash...
> Can anyone point me just a little closer? I'm just trying random stuff at the 
> moment to see if I magically create the thing that MT wants.
> If there's a resource out there that explains the guts of LINQ well enough to 
> start figuring out what's going on under the hood here, I'd love to know 
> about it!
> Thanks,
> bjs
> On Fri, Sep 9, 2011 at 3:15 AM, Pete Macko <[email protected]> wrote:
>>
>> Try putting this in your code and calling it from FinishedLaunching
>> private void MonoTouchForcedCompilationHacks()
>> {
>> {
>> var hack1 = new IFooSession[0];
>> if(!((ICollection< IFooSession>)hack1).Contains(// some bogus lambda or 
>> other thing to force the system to evaluate the collection))
>> {
>> blah blah blah log some crap here or whatever
>> }
>> }
>> }
>> Could put this anywhere I guess, but I got tired of dealing with jit errors 
>> and stuck all this sort of stuff in one place for the sake of organization.
>> Then again, it could be your sample values in the code that are making baby 
>> jeebus cry -- and MT is watching! :)
>> -pm
>> On Sep 8, 2011, at 4:22 PM, Brian Schuth wrote:
>>
>> A couple of months back I hit JIT errors when using LINQ for objects. I was 
>> never able to resolve them, but as the LINQ involved was pretty simple, I 
>> just "unrolled" it into procedural code.
>> Now I'm getting more of them, and I'd really prefer to leave the LINQ alone 
>> if possible. The exception I'm getting today is:
>> Attempting to JIT compile method 
>> 'System.Linq.Enumerable:<ToLookup`2>m__18<JIT20110908.ActualScore, int> 
>> (JIT20110908.ActualScore)' while running with --aot-only.
>> Below is my ProblemLinq.cs file, which contains a class with an Execute() 
>> method that causes this error. I realize there's a lot of interfaces and 
>> classes here; this is a severely dumbed-down version of the actual code, 
>> which is part of a cross-platform reporting library. The code in question is 
>> running in Windows as part of a production product.
>> I've read the "Limitations" section on the xamarin website, and while I 
>> can't say I understand it totally, I don't see that my code is doing any of 
>> the verboten virtualization things; although LINQ does enough magic that I 
>> don't necessarily know the secondary effects of the code.
>> The stack trace from the error this class causes follows the code.
>> I'm running MT 4.0.7 and MD2.6.
>> Am I doing some LINQ thing I shouldn't? Or is MT missing something?
>> Thanks.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to