Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[NET.Standard] UNetWeaver exception

Discussion in '2018.1 Beta' started by VordaRR, Jan 18, 2018.

  1. VordaRR

    VordaRR

    Joined:
    Oct 14, 2017
    Posts:
    9
    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.)
    Code (CSharp):
    1. public class SuchScript : NetworkBehaviour
    2. {
    3.     [SyncVar]
    4.     public int SerializedIntField;
    5. }


    the editor starts failing with an error:

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

    and an exception:;
    Code (CSharp):
    1. UNetWeaver error: SyncVar [System.Int32 SuchScript::SerializedIntField] from netstandard.dll cannot be a different module.
    2. UnityEngine.Debug:LogError(Object)
    3. Unity.UNetWeaver.Log:Error(String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:20)
    4. Unity.UNetWeaver.NetworkBehaviourProcessor:ProcessSyncVars() (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetBehaviourProcessor.cs:2216)
    5. Unity.UNetWeaver.NetworkBehaviourProcessor:Process() (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetBehaviourProcessor.cs:55)
    6. Unity.UNetWeaver.Weaver:ProcessNetworkBehaviourType(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1142)
    7. Unity.UNetWeaver.Weaver:CheckNetworkBehaviour(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1681)
    8. Unity.UNetWeaver.Weaver:Weave(String, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1791)
    9. Unity.UNetWeaver.Weaver:WeaveAssemblies(IEnumerable`1, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1888)
    10. 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)
    11. UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)
    12.  

    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?


    Code (CSharp):
    1. string name = td.Module.Name;
    2.             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")
    3.             {
    4.               Log.Error("SyncVar [" + field.FullName + "] from " + td.Module.ToString() + " cannot be a different module.");
    5.               Weaver.fail = true;
    6.               return;
    7.             }
     
    Last edited: Jan 18, 2018
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,132
    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.
     
  3. VordaRR

    VordaRR

    Joined:
    Oct 14, 2017
    Posts:
    9
    Yes, will do.... the bug is probably in that beefy IF :)
    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:

    Code (CSharp):
    1. public class SuchScript : NetworkBehaviour
    2. {
    3.     [SyncVar]
    4.     public SuchStruct SerializedIntField;
    5. }
    6.  
    7. public struct SuchStruct {
    8.     public int SerializedIntField;
    9. }
    10.