[NET.Standard] UNetWeaver exception

Hello,

I’m messing a bit with the new beta and .NET standard support. I managed to get old projects working in the new beta, i’m having one problem though on the networking side… This error happens even if you put this script into an empty project that is configured for .NET standard…

If you create a simple monobehaviour with a single int SyncVar field (for ex.)

public class SuchScript : NetworkBehaviour
{
    [SyncVar]
    public int SerializedIntField;
}

the editor starts failing with an error:

Failure generating network code.
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)

and an exception:;

UNetWeaver error: SyncVar [System.Int32 SuchScript::SerializedIntField] from netstandard.dll cannot be a different module.
UnityEngine.Debug:LogError(Object)
Unity.UNetWeaver.Log:Error(String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:20)
Unity.UNetWeaver.NetworkBehaviourProcessor:ProcessSyncVars() (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetBehaviourProcessor.cs:2216)
Unity.UNetWeaver.NetworkBehaviourProcessor:Process() (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetBehaviourProcessor.cs:55)
Unity.UNetWeaver.Weaver:ProcessNetworkBehaviourType(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1142)
Unity.UNetWeaver.Weaver:CheckNetworkBehaviour(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1681)
Unity.UNetWeaver.Weaver:Weave(String, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1791)
Unity.UNetWeaver.Weaver:WeaveAssemblies(IEnumerable`1, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1888)
Unity.UNetWeaver.Program:Process(String, String, String, String[], String[], IAssemblyResolver, Action`1, Action`1) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:34)
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)

Can anyone help with explaining a bit why this doesn’t work or is there any way to debug UNET Weaver? I can find the part that throws the exception but i’m having a bit of trouble with the context… Seems like it throws because Int32 is in netstandard.dll? Would it help as a temp fix to wrap the field in a Unity object? ScriptableObject or something?

string name = td.Module.Name;
            if (name != Weaver.scriptDef.MainModule.Name && name != Weaver.m_UnityAssemblyDefinition.MainModule.Name && (name != Weaver.m_UNetAssemblyDefinition.MainModule.Name && name != Weaver.corLib.Name) && name != "System.Runtime.dll")
            {
              Log.Error("SyncVar [" + field.FullName + "] from " + td.Module.ToString() + " cannot be a different module.");
              Weaver.fail = true;
              return;
            }

Hi VordaRR,
This looks like a bug. Could you please submit a bug report with a minimal reproduction case and reply in here with the case #? You can find more information about bug reporting here.

Yes, will do… the bug is probably in that beefy IF :slight_smile:
Anyways because this will stop everything else in the project compiling temporary fix is to make a struct and wrap your fields there. The below code works:

public class SuchScript : NetworkBehaviour
{
    [SyncVar]
    public SuchStruct SerializedIntField;
}

public struct SuchStruct {
    public int SerializedIntField;
}