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

Usages of methods / fields is not shown if called over the interface #245

Open
Blightbuster opened this issue Sep 21, 2023 · 3 comments
Open
Labels
bug Something isn't working

Comments

@Blightbuster
Copy link

dnSpyEx version

6.4.0

Describe the Bug

When analyzing a method of some class TestClass : ITest and checking its usages, dnSpy might show no usages at all since it does not show usages which are invoked by the interface ITest.

How To Reproduce

Create a class which implements an interface and call a method on that class via its interface.

interface ITest { public void MyMethod(); }
class TestClass : ITest { public void MyMethod() {} }

ITest foo = new TestClass();
foo.MyMethod();    // <-- This call will not be found if TestClass.MyMethod is analyzed for usages

Expected Behavior

Its found

Actual Behavior

Its not found

Additional Context

No response

@Blightbuster Blightbuster added the bug Something isn't working label Sep 21, 2023
@GazziFX
Copy link

GazziFX commented Sep 22, 2023

Because decompiler doesn't assume that ITest foo is instance of TestClass, same as virtual methods

@ElektroKill
Copy link
Member

This is because the analyzer analyzes direct usages within CIL bodies, When you compile the code you provided you can see that the call to MyMethod is performed via a callvirt instruction with the operand being the interface method.
image

If you want to find places where TestClass.MyMethod is indirectly called through an interface method, analyze the usages of ITest.MyMethod instead.

@Blightbuster
Copy link
Author

Perhaps its not a bug report but rather a feature request then to show those usages over the interface or abstract class. I'm not sure if that's even possible to implement though as it would require some non trivial analysis and might be out of scope since its already somewhat doable by just looking up the usages of the parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants