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

EnC update on method with custom attribute duplicates the attribute #52816

Closed
vritant24 opened this issue Apr 21, 2021 · 3 comments · Fixed by #53507
Closed

EnC update on method with custom attribute duplicates the attribute #52816

vritant24 opened this issue Apr 21, 2021 · 3 comments · Fixed by #53507
Assignees
Milestone

Comments

@vritant24
Copy link
Member

Given the following method:

[Custom]
public int Method()
{
    return 3;
}
public class CustomAttribute : System.Attribute {}

if there is an edit to change the return statement to return 2, applying the updates from the EnC service leads to 2 [Custom] attributes on Method() during runtime.
Every successive edit adds another instance of the attribute to the CustomAttributes list.

This is an issue in testing because xunit only accepts 1 [Fact] attribute on a method and throws if multiple exist.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 21, 2021
@vritant24
Copy link
Member Author

tagging @tmat

@vritant24 vritant24 changed the title HotReload on method with custom attribute duplicates the attribute EnC update on method with custom attribute duplicates the attribute Apr 21, 2021
@jinujoseph jinujoseph added Area-Interactive Bug and removed Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 28, 2021
@jinujoseph jinujoseph added this to the 17.0 milestone Apr 28, 2021
@davidwengier
Copy link
Contributor

davidwengier commented May 5, 2021

Looks like this is a bug in how we emit attributes. For example, given a generation 0:

Method (0x06, 0x1C):
==============================================================================================================================================================================================================================
   Name           Signature        RVA         Parameters  GenericParameters  Attributes                                                                ImplAttributes  ImportAttributes  ImportName  ImportModule     
==============================================================================================================================================================================================================================
	<... snip ...>
2: 'F' (#31)      string () (#21)  0x00002054  nil         nil                0x00000091 (PrivateScope, Private, Static, HideBySig)                     0               0                 nil         nil (ModuleRef)  
	<... snip ...>

CustomAttribute (0x0c):
====================================================================================================================================================
   Parent                  Constructor             Value                                                                                            
====================================================================================================================================================
	<... snip ...>
4: 0x06000002 (MethodDef)  0x0a000004 (MemberRef)  01-00-00-00 (#56)    

When method F() is modified we get the follow emitting:

CustomAttribute (0x0c):
=========================================================================
   Parent                  Constructor             Value                 
=========================================================================
1: 0x06000002 (MethodDef)  0x0a000006 (MemberRef)  01-00-00-00 (#75/19)  

EnC Log (0x1e):
===========================================
   Entity                        Operation  
===========================================
	<... snip ...>
9: 0x0c000005 (CustomAttribute)  0          

That CustomAttribute entry in the EnC Log is inserting a new row in CustomAttribute (entity 5) rather than updating the existing row (should entity 4).

For attributes in general we should emit rows that edit any attribute that existed in the old compilation, and then rows for new attributes.

Deletes are TBD, but might be unsupported will be emitted by issuing an update that sets the Parent of a CustomAttribute row to a parent of the same kind, but with row id 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants