.NET 4.6 Causes Errors for PUN

Options
Hi, I'm using 2017.1.0f3 on OSX with .NET 4.6 enabled, and I get these errors spammed in the console:

ReflectionTypeLoadException: The classes in the module cannot be loaded.
System.Reflection.Assembly.GetTypes () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/Assembly.cs:406)
PhotonEditor.GetAllSubTypesInScripts (System.Type aBaseClass) (at Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonEditor.cs:745)
PhotonEditor.UpdateRpcList () (at Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonEditor.cs:649)
PhotonEditor.OnUpdate () (at Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonEditor.cs:203)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorApplication.cs:109)

Is there a way I can fix this? I really want to be able to use C#6 with PUN still. Thanks!

Comments

  • [Deleted User]
    edited July 2017
    Options
    Hi @belome,

    maybe I can check that later on a Mac, just did a quick test on Windows which worked for me.

    Besides that it is still marked as 'experimental' on Windows, I currently don't know if there is any difference on OSX. So it seems the best way for now is to use stable .NET 3.5 - sadly.

    Edit: I didn't have any problems building one of the demos on OSX with 'experimental' .NET 4.6 setting. Did you already try to remove all of PUN's content and re-import it?
  • belome
    Options
    Hi, so it turned out not to be an issue with Photon, but rather the .GetTypes() call of my game's assembly. For some reason an unidentifiable Type (from my game's scripts) is returning null and causes .GetTypes() to error out. When I compare to the bad index to the sequence of the valid types, the file that should correspond to that index does not actually exist!

    Here is the work around code that I use instead of the .GetTypes() call in PhotonEditor.cs:

    public static IEnumerable GetLoadableTypes(this Assembly assembly)
    {
    if (assembly == null) throw new ArgumentNullException(nameof(assembly));
    try
    {
    return assembly.GetTypes();
    }
    catch (ReflectionTypeLoadException e)
    {
    Debug.Log("GetTypes() failed for: " + assembly);
    Debug.Log("Getting only non-null types.");
    Debug.Log("Types length: " + e.Types.Length);

    for (int i = 0; i < e.Types.Length; i++)
    {
    var type = e.Types[i];
    if (type == null)
    {
    Debug.Log("Bad type: " + i);
    }
    else
    {
    Debug.Log("Valid Type: " + i + " " + type);
    }
    }

    return e.Types.Where(t => t != null);
    }
    }
    Sorry for the false alarm!