DataObjects-NET/dataobjects-net

Unable to remove backing field

Opened this issue · 5 comments

wizgob commented

Our team is getting random errors during build:
EXEC: Error XW0006 : Unable to remove backing field: type: MyType, property: MyProperty, field:

We are using Xtensive.Orm 6.0.11 with .net 4.7.2.
We are also using Postsharp 2023.0.7

I've been able to attach te debugger to Xtensive.Orm.Weaver.dll: The issue seems to be that RemoveBackingFieldTask.GetBackingFieldName() is returning null.

private string GetBackingFieldName()
{
  foreach (var instruction in property.GetMethod.Body.Instructions) {
    if (instruction.OpCode.Code==Code.Ldfld) {
      var field = (FieldReference) instruction.Operand;
      return field.Name;
    }
  }
  return null;
}

The contents of property.GetMethod.Body.Instructions seems to indicate the assembly was already processed wy the weaver
image

Arguments file passed to the weaver:

/type:.csproj
/backup
/stamp
/pdb
/input:C:\code\Solution\MyProject\obj\Debug\MyProject.dll
[SNIP]

And MyProject.dll from obj\Debug contains the ProcessedByWeaver attribute:
image

This error is a problem for us because the workaround is to clean, the build again the solution which takes 8 minutes because we have a big solution.

I'm not able to reproduce it every time : this error appears randomly.
I suspect something in the build process when doing a partial build of the solution is causing the weaver to get as an input an assembly that is already weaved.

Do you think adding a condition in the weaver do to nothing if the file is already weaved could be a solution?

I have saved the content of an obj folder just before the error and the command to launch the weaver : I can share them privately if needed.

Hello @wizgob,

Sure, I will be glad to tackle the issue for you.

This error usually happens when there is no backing field to delete. So I would like to see the original IL code (or an assembly so I would be able to open it with ILDasm and compare with processed assembly content). I also would like to know what happens when project is built with only weaver - we need to either exclude Postsharp from suspects' list or prove it is guilty (if it is). Understanding what happens first - weaving or "postsharp"-ing, also important.

We had problems with prebuilds by Visual Studio so we added condition for our target like Condition="'$(XtensiveOrmSkipProcessing)'!='true' AND '$(DesignTimeBuild)' != 'true'". I believe we can also check build only with dotnet build or msbuild equivalent. This will move Visual Studio or any other IDE from variables that contribute to the issue. If it happens only for builds from IDE we will gid dipper to this direction.

We can switch to emails for private talk. Write a letter to support@dataobjects.net with title Unable to remove backing field #340, I will understand this is you. I will go on vacation next week so it will be great if we fast-communicate, reproduce and tackle the issue on either our side or workaround/fix it on yours during this week. Any other ways to communicate may be discussed in private talk.

I'll be waiting.

wizgob commented

Hello @alex-kulakov,

I confirm we have the error only with the developer tools, altough me use JetBrains Rider and not Visual Studio.
We have never had the issue with our CI builds.

I think it will difficult to remove Postsharp from our projet : we do not have a reduced project reproducing the issue, we only get it on some builds, and not with all computers.

I'm sending the sample files by email so you can check the IL.

Ok, Let's move to emails and continue talking there.

BTW, you can try following:

  1. clear bin and obj folders completely
  2. open project in Rider

and:

  1. clear bin and obj folder completely
  2. build project with dotnet / msbuild tools
  3. open project in Rider.

It may show some results to think about. First sequence of actions may show you weaving problem if there is some sort of partial build or pre-build done by IDE

@wizgob

I haven't received any emails from you yet. Did you send something?