Code cleanup Optimize using directives in C# will add unneeded casts to object

I am using version 2022.3.2

 

When I run Code Cleanup with the "Optimize 'using' directives" selected then it will add a cast to object in some locations. This seems to happen mostly related to Entity Framework's "public virtual EntityEntry<TEntity> Add<TEntity>(TEntity entity) where TEntity : class" method.

For example, when I use dbcontext.Add(<some_entity>) and then run the cleanup it will get changed to dbcontext.Add((object)<some_entity>) .

Strangely if I use the " public virtual EntityEntry<TEntity> Update<TEntity>(TEntity entity)  where TEntity : class" method this doesn't change when running the cleanup.

0
5 comments
Hello Lance,

thank you for contacting us.
I couldn't reproduce the issue from scratch.
Is there any chance you could provide some sample solution in which the problem is reproduced?
Thank you.
0
Hello Lance,

You can attach it to the message. There's also an option to upload it to our server via https://uploads.jetbrains.com/.
Thank you.
0

Here is the file, Upload id: 2023_02_08_Ao9Da2wN1q1dV3tActq4ZG (file: ResharperCleanup.7z)

It seems I can only reproduce the issue when using AutoMapper and Entity Framework.

Steps to reproduce:

Open Resharper > Options > Code Editing > Profiles and duplicate the built-In cleanup profile so you can edit it.

Under the Optimize Imports > C# Check the "Optimize 'using' directives" > Save.

Open the solution and go to the Repo.cs. The AddField method has this line: _db.Add(destField);

Run Cleanup Code on this file and that line will change to _db.Add((object)destField).

If you uncheck the "Optimize 'using' directives" this will not happen. I'm not sure why this is happening since this option is for using statements.

0
Hello Lance,

thank you for the provided info.
I've filed a corresponding bug report here - https://youtrack.jetbrains.com/issue/RSRP-491394. Please follow it to get the latest updates.
Let me know if you have any more questions.
Thank you.
0

Please sign in to leave a comment.