-
Notifications
You must be signed in to change notification settings - Fork 3
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
Problem accessing Linq methods (extension methods of IQueryable) inside isolated code #54
Comments
I have looked at it, and it seems that the issue is caused by the call to UPDATE: I have added tests to verify that we can indeed shim extensions methods. We can. The problem then lies with how the call to UPDATE: Yep. This is caused by an explicit interface implementation. We can fix this by looking up the method from the interface map associated with the type. Then we also need to update how we find the matching shim. |
@wfrohmberg I pushed a fix for this to the associated branch. This fixes being unable to resolve explicit interface members. Unfortunately, this is not the whole story. Once I got past the explicit interface, I ran into another problem. There are the following methods on arrays:
However, those methods do not actually exist on array. Arrays in C# "implement" IList, IReadOnlyCollection, and IEnumerable via something called SZArrayHelper. This is a special, magic class which the compiler and the runtime use to make it seem like arrays actually implement the mentioned interfaces. However, that's not true. This means that when we attempt to devirtualize a method during a rewrite, the method does not exist on the type nor is it implemented via explicit interface. More info can be found here: https://stackoverflow.com/a/11164210 I will investigate some more and see if there is a solution. |
Hello, I had simular problem, so I tried using commit https://github.com/Miista/pose/tree/54-problem-accessing-linq-methods-extension-methods-of-iqueryable-inside-isolated-code if it solves problem for us as well. Unfortunatelly I think I ran into simular issue with GetHashCode on IEqualityComparer, as with array methods mentioned above. The situation is this:
|
@BigDLA Can you put together a small example? |
I´ll try, but its quite extensive complicated legacy code, so far I wasnt able to replicate it elsewhere. But I will give it another go. :D |
I beleve I managed to reproduce it: https://github.com/BigDLA/PoseDemo.git, just run the console and it should fail when lolObject.LolMethod() is called in isolated code (specifically on line var foo = CollectionClass.SomeStaticMethod(a)) |
@BigDLA I got past the InvalidOperationException. There are no exceptions. Please see below image. However, the key doesn't seem to be in the dictionary any longer. I'm sure this is somehow caused by the rewrite. UPDATE: I was able to get it working successfully if I simply forward calls to I believe this might be a valid way forward given that That said, there seems to be a problem on .NET 6, 7, and 8 with regards to how the IL is rewritten. Most tests fail with "Common Language Runtime detected an invalid program." I'm tracking this is #55 |
@BigDLA It should be fixed in the latest commit on the associated branch. Please verify. |
@Miista It looks like it fixed the reported problem, thank you for the swift reaction. However, I seem to have another problem further down the road, but having trouble pinpointing it. Do you have any tips if it is possible to somehow debug the emmited code? |
@BigDLA Unfortunately, there is no way to set breakpoints in the emitted code. You can define a TRACE constant in the Pose project and any project using it directly. This will output the IL for the code under isolation; not the IL being emitted, however. Putting Can you tell me more about the issue? |
I belive this problem was already issued before in original tonerdo/pose (tonerdo/pose#11) but I think it remained unaddressed. The problem occures when I want to access e.g. standard collection as queryable from inside of the isolated code e.g.:
Isolated code seemed to get null (or at least perceives obtained object as a null).
The text was updated successfully, but these errors were encountered: