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

Code Editor unable to resolve types with [TypeIdentifier] attribute #364

Open
PercyDan54 opened this issue Oct 1, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@PercyDan54
Copy link

dnSpyEx version

https://github.com/dnSpyEx/dnSpy/actions/runs/11113265812

Describe the Bug

Code Editor unable to resolve types with [TypeIdentifier] attribute

How To Reproduce

Create a .NET struct/interface etc with [TypeIdentifier]

namespace Playground;

public class Program
{
    static void Main(string[] args)
    {
        var myStruct = new StructTest();
        Console.WriteLine();
    }
}

[System.Runtime.InteropServices.TypeIdentifier("36EDDFF6-EBFB-41CC-BD63-B84833AA20A1", "Playground.StructTest")]
public struct StructTest
{
    public int Num;
}

Decompile with dnSpy and try to edit code.

Expected Behavior

The type is resolved

Actual Behavior

The type could not be resolved
image

Additional Context

No response

@PercyDan54 PercyDan54 added the bug Something isn't working label Oct 1, 2024
@ElektroKill
Copy link
Member

Hi,

this looks to be related to the special handling of TypeIdentifierAttribute by Roslyn where it does not allow cross-assembly references to such types which conflicts with how the dnSpy code editor works.

dnSpy takes the original file, removes the type you are currently editing, injects an InternalsVisibleTo attribute, and adds this new file as a reference to a project which contains only the class code for the class you are editing. This means that we access that type with TypeIdentifierAttribute using a cross-assembly reference which is blocked by Roslyn.

The way to fix this will probably mean patching the assembly we reference even more to remove the TypeIdentifierAttribute from the types. The current patcher works on raw bytes and the custom attribute format is quite complicated so I will see what I can do with it to get rid of the TypeIdentifierAttribute.

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

2 participants