-
Notifications
You must be signed in to change notification settings - Fork 127
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
Arguments to Custom Attributes Do Not Update Upon Type Rename #576
Comments
I'm running out the door so apologies in advance if this isn't enough context. Happy to provide more if required. |
Thanks for the detailed report. The reason this happens is because the binary format of custom attribute (CA) signatures is weird (read: incredibly stupid). Unlike everything else in the .NET file format, CAs store type arguments as fully qualified name strings as opposed to metadata tokens. AsmResolver currently parses these strings and creates We could consider refactoring Open for suggestions. |
In the Name & Namespace properties of TypeDefinition, add: if (check is attribute type) { get all CA & rename all typesigs in CA } |
Note: We need to keep in mind that any type |
I unfortunately don't have any recommendations on how to approach this problem; however, I do really appreciate the thorough response. I could attempt to go about tracking/updating this in my own project if there's some function calls that are exposed for me to update those arguments. Otherwise, I'll just document it as "unsupported" in my project and move on. Also, huge fan of the project. It's a tremendous accomplishment. |
It could be an opt-in specification during loading, or lazily inferred by setting |
Or maybe |
However, this ultimately doesn't seem much different from external references. If you rename a type in one module, the references in another module are not (currently) updated. |
I would expect that to change, with workspaces, right? Isn't that kind of tight coupling the point? |
Lazy inference, if possible/feasible, sounds like the best option from an UX standpoint. I would like to avoid adding yet another option/flag/method that can easily be forgotten by an end-user.
Sort of. Workspaces (if it ever takes off) is supposed to be a separate analysis/refactoring layer on top of the current metadata model. In this perspective, there is an argument to be made to keep things as-is, though for better UX we probably shouldn't as this affects two type descriptors defined in the same module. Side note: When linking serialized type signatures in CAs to serialized type definitions in metadata, we may want to consider the original namespace+name pair of the type definition, or else users may rename the type definition first before initializing the CA signature and thus break the link before AsmResolver gets the chance of linking the related types together. As this pertains to just serialized metadata only, we can probably get this information from the underlying type def row and backing |
AsmResolver Version
4.11.2
.NET Version
.NET 6.0
Operating System
Windows
Describe the Bug
Class types that use a custom attribute type decorator do not update the class type's custom attribute's fixed arguments to reflect the attribute type's new name upon renaming.
This can be explained better with code. Let's suppose we have two type definitions (
TypeDefinition
) for classesClassA
andClassB
.ClassB
has an attribute decorator ofMyCustomAttribute
which takes one argument, a type.ClassB
is instantiated as follows:Let's say the
TypeDefinition
variable forClassA
is stored as a variable as follows:If I were to rename
ClassA
via:You would see that the arguments for the
CustomAttributes
field onClassB
'sTypeDefinition
object does not update to reflect the new argument ofClassC
.How To Reproduce
Create an example project with the following file:
Compile to
TestProject.exe
. Then, in a separate project leveragingAsmResolver
, use the following code to update theClassA
type definition name:If you were to inspect
ClassB
's type definition via:You would see that the signature here still references
ClassA
which no longer exists in the assembly.Expected Behavior
The arguments to custom attribute decorator of classes getting updated as required. For example,
ClassC
should now populate the arguments of the signature in the previous code instead ofClassA
.Actual Behavior
ClassA
remains referenced as an argument to the attribute constructor even though this type no longer exists.Additional Context
No response
The text was updated successfully, but these errors were encountered: