Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Enter the 2020.2 Beta Sweepstakes for a chance to win an Oculus Quest 2.
    Dismiss Notice

Unity.Collections exception

Discussion in 'Data Oriented Technology Stack' started by wobes, Dec 12, 2018.

  1. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    Good day.

    Is there any way to resolve an issue with the dublication of System.Runtime.CompilerServices.Unsafe.dll
    I wish to use another version of it but I can't because it conflicts with the built in version in Unity.Collections package. When I drop another version of 4.5.0 unsafe library it throws the exception. I have another library that has dependency on the 4.5.0 unsafe library not the Unity.Collections one. So there should be a feature to remove the library that in the the package.

    Library\PackageCache\com.unity.collections@0.0.9-preview.10\Unity.Collections\UnsafeUtilityEx.cs(13,24): error CS0433: The type 'Unsafe' exists in both 'System.Runtime.CompilerServices.Unsafe, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'



    Thank you.
     
    Last edited: Dec 12, 2018
  2. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
  3. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    Temporary fixed by deleting the dll from the Library/PackageCache folder.
     
    andywatts likes this.
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,510
    Try using Override References button on your .asmdef and manually choose the right .dll for your assembly
     
  5. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    I don't have any .asmdef in my project. And adding one and setting to override doesn't work too.
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,556
    What happens if you turn off auto including on the .dll? and auto referencing? [After also including it in the override of the asmdef]
     
    wobes likes this.
  7. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    Have multiple errors and everything is broken.
     
  8. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
  9. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,556
    I already did and it worked fine - got rid of the error. Hence my suggestion.

    However I did not have any libraries referencing it or attempt a build so I couldn't confirm it'd work.
     
  10. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    Solved by disabling auto reference, auto including and creating an asmdef file with overriding a new dll.
    However still requires old .dll to be removed in order to properly create asmdef.
     
    Can-Baycay likes this.
  11. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    Resuming this as I have the same problem. I can't manage to tell to my asmdef to use the Unsafe.dll I want to use (together with buffers.dll and memory.dll) without clashing with other dlls

    PrecompiledAssemblyException: Multiple precompiled assemblies with the same name System.Runtime.CompilerServices.Unsafe.dll included for the current platform. Only one assembly with the same name is allowed per platform.

    Edit: it seems that the dll auto reference option must be disabled too, but it doesn't help, even if I do so, it still conflicts with the existing dlls
     
    Last edited: Dec 16, 2019
  12. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,039
    It conflicts because the collections package is pulling in it's version. The simplest solution with the least impact on your project is just copy the version you want over what Unity provides. Assembly definitions cannot solve this problem.

    It's also solvable with aliases. That's really what packages should be doing IMO.
     
    andywatts likes this.
  13. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    Last edited: Dec 17, 2019
  14. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    OK solved with asmdefs only, please check these configs:

    upload_2019-12-17_12-58-50.png

    upload_2019-12-17_13-2-12.png

    note everything is unchecked with the select platform for plugins. If there weren't the Unsafe dll from the other packages, it wouldn't have worked, however this is the only way I found to make the buffer and memory dlls work when other packages include unsafe. dll. Deleting the unsafe.dll will end up in a signature failure exception at run time (buffer and memory won't find the dll). I have no much clue about what's really going on, so consider this a work around.
     
    Last edited: Dec 17, 2019
    MNNoxMortem and computas like this.
  15. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    600
    Just to let some steam off: I hate this so much and it has cost me already so many hours since the day asmdef have been released and today I just once more horribly ran into it with a version incompability between an auto referenced System.Runtime.CompilerServices.Unsafe.dll between Collections and MessagePack (4.5.0 vs 4.5.1).

    Why the hell does a package, where I do not have control over it, add dlls and mark them as auto referenced in the first place. Why don't I get control over it? Why is the whole asmdef thing still so incredibly unstable after all that time that unity fails to compile and crash hard to desktop because of that cycle and then falls back to the old default csproj folder based structure, although it should clearly know that it should expect .asmdef based project files as it HAD JUST FAILED COMPILING THEM which once more causes a compiler error because obviously those csproj obviously are not set up correctly regarding their dependencies, as how in the world could they even be... Why does unity even dare to override my manually and careful setup .asmdef file such that I have to revert the file via vcs because it fails to resolve that cycle? If you do that for the auto generated old way to structure projects, fine, but for project and dependency definition files where you expect me to set them up: do not overwrite them...

    Sorry. I know, this is just a rant and not super constructive, but I just once more are spending hours to fix some minor version upgrade of a package that by no means should interfere with anything from a unity package...
    Edit: Okay, now I feel better :) Hope everyone else here had a better day than I did.

    Edit 2: @sebas77 by the way. While this is a workaround it also means you will not have this particular dll in your build and referenced but the version from the package cache. This could cause a version discrepancy and nasty bugs which you only notice once the dll is loaded during Runtime. However - thanks for the idea, I will also do that for now and hope nothing breaks horribly soon.
     
    Last edited: Jan 26, 2020
    ConAim likes this.
unityunity