Search code examples
c#unity-game-enginedotfuscator

Prevent dotfuscator from reusing field names from parent class


We are having a weird issue between what looks like a Unity bug and the result of an obfuscated DLL by Dotfuscator community. The problem is related to what is described here: https://forum.unity.com/threads/what-does-this-error-mean-exactly.122136/

In essence, the problem is that code like the following:

public class MyParentClass : MonoBehavior {
  private int foo;
}

public class MyChildClass : MyParentClass {
  private int bar;
}

will get obfuscated like

public class A : MonoBehavior {
  private int a;
}

public class B : A {
  private int a;
}

while this is perfectly valid C# code, it confuses Unity which tries to serialize all the fields, even if they are private and not marked as Serializable and it spits out the "The same field name is serialized multiple names in the class or it's parent class. This is not supported" error. It does not prevent the project from running, but it's still messy.

The easy solution would be to prevent renaming for those fields, but we would like to avoid it (that's the point of using obfuscation after all...). Is there a way to configure dotfuscator to, for example, prevent it to reuse the same names for fields in inheritance hierarchies ?


Solution

  • It appears it was a bug with Unity Burst. It has been fixed in Burst 1.8.4

    https://docs.unity3d.com/Packages/[email protected]/changelog/CHANGELOG.html