Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

IL2CPP error in entworking generated code

Discussion in 'Multiplayer' started by Ashkan_gc, Feb 23, 2016.

  1. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,102
    I have two projects on uNet which have pretty similar code. Maybe about 50% of the code is the same and all features used are the same. One of them builds successfully, when building the other for WebGL using IL2CPP, The IL2CPP compiler gets the following error in the generated code for NetworkWriter classe

    ---

    IL2CPP error for method 'System.Void Unity.GeneratedNetworkCode::_WriteArrayString_None(UnityEngine.Networking.NetworkWriter,System.String[])'
    Additional information: Build a development build for more information. An item with the same key has already been added.
    il2cpp.exe didn't catch exception: System.ArgumentException: An item with the same key has already been added.
    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
    at Unity.IL2CPP.Metadata.VTableBuilder.SetupClassMethods(List`1 slots, TypeDefinition typeDefinition, Dictionary`2 overrideMap)
    at Unity.IL2CPP.Metadata.VTableBuilder.VTableForType(TypeDefinition typeDefinition, Dictionary`2 interfaceOffsets, Int32 currentSlot)
    ---


    It seems the method is added twise for some reason, I removed all usages of string[] from RPCs (which was only one actually) but again it got the same error for serializer of one of my classes which are children of MessageBase, The same class works in the other project.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,741
    @Ashkan_gc

    Can you submit a bug report with this project? This certainly looks like an error in IL2CPP that we need to correct.
     
  3. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,102
    Hi
    My employer submitted the project and he received this case number in the email , 773323

    The exact situation is like this, the code which is generating the error is similar in both projects. When I commented this RPC which had a string[] then another class GameRoom got the same issue, I wrote a serializer for GameRoom instead of relying on the autogenerated one but it didn't fix the issue.

    I tried to look for any differences between build settings of the projects but I could not find any. I can not see the generated code so I can not guess why the files are being scanned twise or something like that. but as you can see the thing happening is that some methods in NetworkWriter like WriteGameRoom_none or WriteArrayString_none are being added a second time to the vtable of the NetworkWriter class. Other than this the log doesn't provide any information which I can find useful. Probably by taking a look at generated code you can find out what is wrong with this. I hope since this affects uNet and IL2CPP both, we find a fix not too late. :)

    Many thanks
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,741
    @Ashkan_gc

    Thanks, we will have a look at this bug report.
     
  5. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,102
    So for the information of others until it gets fixed and spits out better error messages. My problem was that on a NetworkBehaviour I implemented the GetChannel virtual method and also used the [NetworkSettings] attribute both on the script so unity generated the same method again for me and it was causing issues.
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,741
    @Ashkan_gc

    Yes, this is bad on our side that there is no warning or error about the duplication, and in fact an assembly with invalid IL is produced (hence the problem il2cpp.exe has converting it). We'll attempt to provide better diagnostics in the editor for this case.
     
  7. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,102
    @JoshPeterson thanks a lot for your help actually. WebGL networking is killing me actually but at least this is fixed now. Since all of my messages which were high frequency were unreliable and in websockets there is no unreliable messages I am getting disconnects even updating 6 times per second :(

    About the above error, I think if you make users capable of examining the generated code it would help in solving similar issues. AutoGenerated code is similar to magic in some ways and when you don't see what is exactly going on, it feels worse however in the uNet case this is the best solution. At least if you put notes in the doc on what assembly we should drop in reflector to see the autogenerated code, it would be good.
    Also a chapter on WebGL related problems and how to handle realtime networking there, which connectionConfig parameters and ...
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,741
    @Ashkan_gc

    Thanks for these suggestions. In general, any script code in the project will be compiled into UserAssembly-<something>.dll. You can always drop this assembly into a tool like ILSpy to see the generated code. But I agree, something nice that that workflow would be better.