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

private SyncListStruct hits MethodAccessException in .Net 4

Discussion in '2018.2 Beta' started by Arkade, Jun 11, 2018.

  1. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    654
    I'm just trying .Net 4 as a stepping stone to trying the incremental compiler. However I'm still using the normal compiler atm (in this project).
    When I switched from .Net 2 to 4.x (and updated an Asset), I get an error from part of the networking suggesting something's changed there.

    Code (CSharp):
    1. MethodAccessException: Method `UGS.unityutils.net.NetworkNamedNotifier+NamedNotifierList.SerializeItem(UnityEngine.Networking.NetworkWriter,UGS.unityutils.net.NamedNotifierId)' is inaccessible from method `Unity.GeneratedNetworkCode._WriteStructNamedNotifierList_NetworkNamedNotifier(UnityEngine.Networking.NetworkWriter,UGS.unityutils.net.NetworkNamedNotifier/NamedNotifierList)'
    2.   at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_throw_method_access(intptr,intptr)
    3.   at Unity.GeneratedNetworkCode._WriteStructNamedNotifierList_NetworkNamedNotifier (UnityEngine.Networking.NetworkWriter writer, UGS.unityutils.net.NetworkNamedNotifier+NamedNotifierList value) [0x0001f] in <4808fd817ec644b0a5fcf6e7b7a6609f>:0
    4.   at UGS.unityutils.net.NetworkNamedNotifier.OnSerialize (UnityEngine.Networking.NetworkWriter writer, System.Boolean forceAll) <0x642b4f60 + 0x00072> in <4808fd817ec644b0a5fcf6e7b7a6609f>:0
    5.   at UnityEngine.Networking.NetworkIdentity.UNetSerializeAllVars (UnityEngine.Networking.NetworkWriter writer) [0x00015] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:452
    6.   at UnityEngine.Networking.NetworkServer.SendSpawnMessage (UnityEngine.Networking.NetworkIdentity uv, UnityEngine.Networking.NetworkConnection conn) [0x0006d] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1345
    7.   at UnityEngine.Networking.NetworkServer.ShowForConnection (UnityEngine.Networking.NetworkIdentity uv, UnityEngine.Networking.NetworkConnection conn) [0x00013] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1171
    8.   at UnityEngine.Networking.NetworkConnection.AddToVisList (UnityEngine.Networking.NetworkIdentity uv) [0x00010] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:550
    9.   at UnityEngine.Networking.NetworkIdentity.AddObserver (UnityEngine.Networking.NetworkConnection conn) [0x000f0] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:843
    10.   at UnityEngine.Networking.NetworkIdentity.RebuildObservers (System.Boolean initialize) [0x0009d] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:882
    11.   at UnityEngine.Networking.NetworkServer.SpawnObject (UnityEngine.GameObject obj) [0x000d0] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1301
    12.   at UnityEngine.Networking.NetworkServer.Spawn (UnityEngine.GameObject obj) [0x00018] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1522
    13.   at UGS.unityutils.net.NetworkPooled.completeServerSpawning () [0x00007] in D:\Users\Rupert\Dropbox\Dev\VRToy56Direct\Assets\01UGS\02Code\Util\net\NetworkPooled.cs:20
    14.   at UGS.vrtoy.interaction.InfoPanelManager.CmdShow (System.String nameOfTargetToBeInFrontOf, System.Single offset, System.String url, UGS.unityutils.net.NamedNotifierId requestor) [0x000d3] in D:\Users\Rupert\Dropbox\Dev\VRToy56Direct\Assets\01UGS\02Code\vrtoy\interaction\InfoPanelManager.cs:66
    15.   at UGS.vrtoy.interaction.InfoPanelManager.CallCmdShow (System.String nameOfTargetToBeInFrontOf, System.Single offset, System.String url, UGS.unityutils.net.NamedNotifierId requestor) [0x0001c] in <4808fd817ec644b0a5fcf6e7b7a6609f>:0
    16.   at UGS.vrtoy.interaction.InfoPanelManager.show (UnityEngine.GameObject targetToBeInFrontOf, System.Single offset, System.String url, UGS.unityutils.net.NetworkNamedNotifier+NamedNotifierReceiver requestor) [0x00044] in D:\Users\Rupert\Dropbox\Dev\VRToy56Direct\Assets\01UGS\02Code\vrtoy\interaction\InfoPanelManager.cs:45
    17.   at UGS.vrtoy.toys.orrery.Constellation.showInfoDialog () [0x00050] in D:\Users\Rupert\Dropbox\Dev\VRToy56Direct\Assets\01UGS\02Code\vrtoy\toys\orrery\Constellation.cs:189
    18. (Filename: <4808fd817ec644b0a5fcf6e7b7a6609f> Line: 0)
    The short version is that on that prefab that just got `NetworkServer.Spawn()`ed, there's an inner class declared as:

    Code (CSharp):
    1. private class NamedNotifierList : SyncListStruct<NamedNotifierId> {}
    This worked fine in .Net 2. It fails in .Net 4.x.

    When I decompile the .Net 4 generated code, I see it's simply calling `Serialize()`.

    It's easy enough to work around -- make it public (it's also in a namespace that isn't "Unity" so I assume making it `internal` would also fail).

    Just me?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    This sounds like a bug on the Unity side. You should not need to change any code to make it work with .NET 4.x. I wonder if the UNET generated code is simply incorrect, as the old runtime incorrectly accepted it.

    Can you submit a bug report? Thanks!