Search Unity

0.51 InvalidOperationException: Cannot find Unity.NetCode metadata reference for assembly

Discussion in 'NetCode for ECS' started by tertle, Jun 15, 2022.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Code (CSharp):
    1. error Netcode: System.InvalidOperationException: Cannot find Unity.NetCode metadata reference for assembly BovineLabs.Saving
    2.    at Unity.NetCode.Generators.TemplateParser.ParseTemplatesFromMetadata(GeneratorExecutionContext context, IList`1 templates)
    3.    at Unity.NetCode.Generators.TemplateParser.ParseTemplates(GeneratorExecutionContext context)
    4.    at Unity.NetCode.Generators.NetCodeSourceGenerator.Generate(GeneratorExecutionContext executionContext, Candidates candidates, IDiagnosticReporter diagnostic)
    5.    at Unity.NetCode.Generators.NetCodeSourceGenerator.Execute(GeneratorExecutionContext executionContext)
    6.  
    I'm having an immediate issue after updating to 0.51 where if I have an assembly that does not use netcode is referenced by an assembly that does use netcode I just get the above locking error. It's fixable by making the assembly reference Netcode.

    e.g.
    GameAssembly
    - References Netcode
    - References Saving

    SavingAssembly
    - References nothing

    Above error
    Adding Netcode to SavingAssembly fixes error.
    This happens in a brand new project just adding in in 2 existing libraries.

    -edit- actually I think it might be reversed

    Core references Netcode
    Saving references Core

    Even if saving does not use any Netcode it needs a reference on Netcode otherwise errors
     
    Last edited: Jun 15, 2022
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    What editor version are you using?
    We fixed that problem recently and I'm honestly quite surprised you have that issue. Since there are tons of assemblies that does not used NetCode that are processed without problems.
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Latest 2021.3.4f1 (latest)

    Packages

    Code (CSharp):
    1.    "com.unity.burst": "1.7.2",
    2.    "com.unity.entities": "0.51.0-preview.32",
    3.    "com.unity.netcode": "0.51.0-preview.32",
    4.    "com.unity.physics": "0.51.0-preview.32",
    5.    "com.unity.rendering.hybrid": "0.51.0-preview.32",
    I had it on 4-5 separate assemblies (of like 50) when upgrading - including 2 test assemblies.
     
    Last edited: Jun 16, 2022
  4. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    mmm.. I tried doing the same in a very small project with two assemblies like you mentioned.
    But I have zero error. The setup looks like:

    AssemblyWithNetCode
    ref Entities
    ref NetCode
    ref Burst
    ref Collection
    ref Mathematics
    ref AssemblyWithoutNetCode

    AssemblyWithoutNetCode:
    ref Entities
    ref Burst
    ref Collection
    ref Mathematics

    The assemblies only contains one file, with one component each.
    The assembly that has netcode references also replicate that component (he has ghost fields)
     
    Last edited: Jun 17, 2022
  5. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    Also, given the error you get I suspect the problem is elsewhere. In particular, the compilation pipeline is passing/running (erroneously) the NetCodeSourceGenerator to assemblies that does not reference netcode. That is wrong, it is not the expected behaviour. This is why that method trigger an exception.
    We can fix in netcode package by adding some extra checks and skip the problem altogether. But I would like to be able to repro the problem myself first.
    I might suspect that is an issue due to the upgrade / update. If I start from scratch a project I might not be able to see any issue there.
    Can you please check that if you now, after you updated everything, remove all the netcode reference, delete the library folder and re-import the project, everything works?
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Actually I got the error in a a brand new empty project copying in libraries in. When upgrading my project I was just getting a generic errors that didn't help at all and wouldn't compile (even though I deleted entire library before upgrading).

    Luckily my project is extremely modular so instead I created a fresh project and slowly brought libraries into it until I got errors. Once I fixed these up and copied back changes to original project it compiled fine.

    When I get off from work I'll try remove the references I added and see if it still fails.

    I can probably rollback to my pre-upgrade state, test if I can repo the same thing in an empty project and if so just send you a library that fails.
     
  7. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    Thanks that will help understand what it is going on.
    But in any case, I have already an hot-fix for the problem that we can land to you asap.
     
  8. mcdmags

    mcdmags

    Joined:
    May 13, 2018
    Posts:
    1
    Hi, have the same issue. can you also point me to your hotfix @CMarastoni ? thanks
     
  9. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    Can you guys please report this issue using the UnityEditor bug report ? So we can keep track of it.
    I was unable so far to repro the problem, but I'm probably doing something different you are. Would be great if you can provide a project (hopeufully a test project) where the problem occurs.

    In order to give you the hot-fix I need to re-compile the netcode-generator and push some dlls in the forum.
    That is usually not what I would like to do, I would prefer to release a proper package fix instead (seem more legit).
    Let me see what the ETA for a package update would first.
     
  10. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Oh sorry I forgot about this as once solved it was no longer an issue.
    I'll try find some time to see if my expected repo works.
     
  11. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I'm also getting the error with that kind of setup

    AssemblyA references NetCode
    AssemblyB references AssemblyA
    -> this gives me "Cannot find Unity.NetCode metadata reference for assembly AssemblyB"

    But as soon as AssemblyB also explictly references NetCode, the error goes away
     
  12. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    Hi Phil,
    Can you please share the project (or a similar setup) where the problem occur?
    I tried doing the same in a new project or even in older ones but I'm not able to repro it, even though I have a similar setup.
    Question for you: when you got this problem, there was some script error or api update or your were in safe-mode?

    So, since there are already 3/4 persons that are getting this issue I decided to publish an hot-fix here (even though is not the best but lets try).
    Attached you'd find the new compiled version of the source generator that should fix that issue.

    Please (if you didn't already) move the com.unity.netcode from the Library/PackageCache into your package folder (or another directory and then set the manifest accordingly) and unzip the dlls into the com.unity.netcode/Runtime/Gen folder (where they currently are)

    Could you also please let me know if that fix your problems?
     

    Attached Files:

  13. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    After applying the hotfix, I'm getting this error:
    First line says "Cannot load template .../GhostComponentSerializer.cs" and "Package com.unity.netcode not found", but GhostComponentSerializer.cs does exist at the specified path, and my custom netcode package is detected by the package manager

    EDIT: actually, I get this same error even when I just copy the netcode folder into my Packages folder and remove netcode from my package manifest, without applying the hotfix. I might be doing something wrong?

    I also haven't been able to repro in a new project, even when starting out in 2020.3 and then upgrating to 2021.3
     
    Last edited: Jun 26, 2022
  14. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    ohh, that is not what I was expecting to see, I apologies, I tried my self the same fix but I didn't get that error. I will by moving netcode in the package folder and fix the problem.
     
  15. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Not sure if this is the issue you are seeing, but there is one big pitfall with doing this - when you copy the folder into the package folder you must rename it so the path is `Packages/com.unity.netcode/` - if you just move it and keep the `@0.51.0-preview` in the folder path it will not work.
     
  16. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    @CMarastoni
    I see, I've tried it again and now I can confirm the fix works. I was able to remove the NetCode reference from some of my assemblies and the errors don't appear anymore. Thanks!

    I won't be able to use the hotfix for my project specifically, because it's an asset store project. But I'd be interested in knowing if there are plans to release an official package update containing the fix in the near future?
     
  17. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    Yes, definitely.
     
    PhilSA likes this.
  18. MagiJedi

    MagiJedi

    Joined:
    Apr 17, 2020
    Posts:
    32
  19. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    Is the package embedded in the Package folder? In the latter, did you remove the "@XXX@ suffix (the package name should be com.unity.netcode)
     
  20. MagiJedi

    MagiJedi

    Joined:
    Apr 17, 2020
    Posts:
    32
    Since there is no .../Runtime/Gen folder, I set it up this way:

    upload_2023-2-15_13-14-50.png

    On a hunch, I also tried deleting the existing "NetCodeSourceGenerator.dll" and renaming the Hotfix file "Unity.NetCode.SourceGenerators.dll" to match, but that didn't make a difference.

    In both cases, Unity boots into safe mode and gives me variations on:
    Packages\com.unity.netcode\Runtime\Physics\PhysicsVelocityVariant.cs(32,34): error CS0433: The type 'GhostPrefabType' exists in both 'GeneratorShared, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Unity.NetCode, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

    upload_2023-2-15_13-17-56.png
     
  21. MagiJedi

    MagiJedi

    Joined:
    Apr 17, 2020
    Posts:
    32
    Quick follow-up @CMarastoni - I created a new project and only installed Entities/Entity Graphics/Unity Physics/Netcode for Entities in that order. Restarted Editor. Then I created a new scene, a new C# script, named it as per the directions in the Getting Started -> Networked Cube page, copy/pasted the code and the assembly errors come right up.
     
  22. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    I will check with 0.51. Just be aware though that 0.5x are not LTS supported version, so there would be no backports or fixes for it.
    But if we find a fix or workaround for this problem, I will post here. Let us check.
     
  23. MagiJedi

    MagiJedi

    Joined:
    Apr 17, 2020
    Posts:
    32
    Thanks again for your follow-up. I fear I may not have been clear.

    I'm having this issue on Entities 1.0 latest, not on .51. I only posted here because it was the only thread I found mentioning the issue.
     
  24. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    Oh, alright, I misunderstood that it was 1.0. I saw 0.51. My bad. Could you please open a case for it?
    This is the preferred way for us to track issues.
     
  25. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    @MagiJedi
    Hey! So, I was looking to your directory
    upload_2023-2-15_13-14-50-png.1198294

    So I'm a little confused. You are moving (or using) the com.unity.netcode package in the Package folder (fine). But then, I dunno why, you are also adding another generator to the Runtime/SourceGenerator folder:

    These dlls aren't the package and should not be added at all! Please remove them.
    Why are you adding them to the netcode package when there is not need ?

    This of course generate all the possible problems: you are in practice generating all serialization code twice (the generator does similar things) and this is causing the problem you are seeing.
     
  26. MagiJedi

    MagiJedi

    Joined:
    Apr 17, 2020
    Posts:
    32
    Sorry if that was confusing. Basically, I encountered the issue mentioned earlier in this thread (except I'm on 1.0) and tried out the proposed solution/hotfix directions you had previously given. However, the folder names didn't match so I just tried to guess where it would fit in the new folder structure (which is where that screenshot was taken from).

    Regardless, the issue happens on a new project installing everything from package manager and not moving any folders/files around or trying to use the hotfix.

    I hope this clarifies. Thank you for the follow up!
     
  27. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    897
    I tried again to follow the guide, step by step But no error. If you a project where you can repro it, please open a case and attach it. Thanks