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

Editor assembly loading issues - "unloading broken assembly", "could not load signature"

Discussion in 'Experimental Scripting Previews' started by Bortos, Oct 2, 2019.

  1. Bortos

    Bortos

    Joined:
    Apr 6, 2016
    Posts:
    12
    I'm trying to get a bunch of the Microsoft.Extensions.* libraries in Unity and I've found it would work fine in a small quick project, but complains when I started separating them into different folders. It builds, but the editor complains:

    upload_2019-10-3_1-0-42.png

    The above errors do not seem to prevent a successful build, and the build demonstrates the libraries are working successfully.

    I have found that the editor doesn't report errors if all the assemblies are within the same folder:

    upload_2019-10-3_1-4-26.png
    Above is good! No errors

    upload_2019-10-3_1-4-53.png

    Above is bad, and the editor isn't happy.

    Both projects produce a build fine, but I'd rather get rid of the errors and enable the assemblies to be nested in their own folder - as I am making them modular through Unity's packages.

    I have attached a .zip file with both projects.

    Can I do anything to prevent these errors?
     

    Attached Files:

    Last edited: Oct 2, 2019
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    This looks like a bug in the editor assembly loading logic. Can you file a bug?
     
  3. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    266
    I believe the build works correctly because all of the assemblies get moved to the same folder (Data/Managed), so there are no issues resolving them.
     
  4. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @Tautvydas-Zilys @JoshPeterson @joncham @jonas-echterhoff

    I have the exact same problem. Initially I thought it was because of the Package manager but in reality it has to do with the separation by folders. In that thread I have a bug report and in successive posts a couple of examples in a very simple project.

    We are using UPM internally for our code base and this is stopping us completely.

    https://forum.unity.com/threads/err...on-which-folder-it-is-in.766583/#post-5113808
     
  5. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
  7. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    Case 1196416

    Case 1193928
     
  8. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
  9. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Unfortunately that's not in my area of expertise - another team will be looking at it.
     
  11. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    Any news? It's been two months since this thread creation.

    Can you reach that team @Tautvydas-Zilys ?
     
  12. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Most likely its because of strong named assemblies and versions.

    So the references that those assemblies are compiled against needs to match what is in the project.
    We recently got a similar bug reported: https://issuetracker.unity3d.com/is...when-assembly-dependency-is-in-another-folder

    I added a better log message explaining what the issue is, hoping to get that included in the 2019.3 release. That it works when in the same folder is puzzling since it should be the same. But our team handling mono is notified.

    I used dotPeek to add all the assemblies, and compare the version that are referenced. Other tools can do the same I guess, ilspy is also a good tool
     
  13. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @HaraldNielsen What I understand is that you aren't going to fix my original issue and instead you see going to "break" what works if they are in the same folder.

    In this case the supposed "fix" it's going to result in more problems for us...

    We hoped you will fix the original issue that prevented us to have assemblies in different folders...

    On a traditional console, wpf or asp you can have higher dependencies like >= 1.0.0 for example and they are the same assemblies that I'm manually adding to Unity.

    It should work...
     
  14. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    @bdovaz we are going to give a much more descriptive error so you can understand why you are getting these errors, and how to fix it. Right now you need to use external tooling for finding out why. You can disable our validation, and the error that we give also states that so the user can choose to ignore it, but that could lead to runtime errors.

    On traditional application the same rule applies, but you can override these bindings so it will load another version than what its compiled against (https://docs.microsoft.com/en-us/dotnet/framework/deployment/how-the-runtime-locates-assemblies), we dont support this, but you can make a feature request supporting it in the runtime.
     
  15. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Last edited: Nov 29, 2019
  16. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    Thanks but the ideal solution as I said below is to be able to configure bindingRedirects as in a traditional application.

    What validation are you talking about? How can I disable it? What consequences can it have?

    This would be the real solution.

    Think that since Unity supports .NET 4.x and .NET Standard 2.0 it is very common in projects that are not games to do integrations that require libraries and in Nuget we have an immense amount of very popular packages to use with Unity. In that case is when we find conflicts that a "Package A" can have a dependency of >= 1.0 of "Package B" and "Package C" one of >= 1.1 of "Package B" and with the bindingRedirects we could solve it, otherwise it would be impossible.

    Of course I'm talking about processing a "Publisher Policy File" (bindingRedirects) when compiling in both Editor mode (hitting play) and Player mode (published build like an *.exe).
     
  17. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @HaraldNielsen I recently saw in 2020.1a16:

    Scripting: Emit error when validating assembly references for strong named assemblies. (1196416)

    https://issuetracker.unity3d.com/is...when-assembly-dependency-is-in-another-folder

    But this "correction" does nothing but annoy us because before it did not emit the error and it worked, now I understand that it is not going to work.

    Could you take a look to see if we can create a "Publisher Policy File" (bindingRedirects) so that we can manually manage all this as it is done in Visual Studio?
     
  18. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    @bdovaz yes its true that the error will also result with dll's that did not give any errors before (because they where in same directory), but we added this error anyway because the information is valuable (This is not the first time we got an bug because of strong named assemblies and version mismatch). And you can choose to turn of the validation directly on the plugin, in its inspector.

    I also agree that we should do the Publisher Policy File / bindingRedirects, its the correct thing to do, and would give a lot of value. Already talked with the VM team about about it.
     
    jashan likes this.
  19. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    Ok, thanks.

    Please, keep me updated with that feature.

    I understand that this feature will also be evaluated before compilation inside editor and not only when publishing a build.
     
  20. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @HaraldNielsen many month later I recently got a reply on case 1193928 and but I'm told they're not capable of reproducing it and they immediately closed it.

    The explanation they give me is very absurd. They tell me that the 12.x version of assembly B (Newtonsoft.Json) is not the version that assembly A (Microsoft.Extensions.Configuration.Json) expects, which is 11.x. But it is precisely because I reported it that this error only occurs when they are in different folders and not in the same one.

    It is a behavior that has to be homogeneous because if it depends on the hierarchy of folders it has to be a bug.

    Besides, it should support policy files to make a bindingRedirect and definitely fix this inconsistent behaviour.
     
  21. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    I got pinged after you linked to this post in the bug. And its not closed any more
     
    bdovaz likes this.
  22. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @HaraldNielsen @xoofx

    Case 1193928
    Case 1196416

    I've tested in 2020.1.0b5 and it keeps failing, in fact, now it doesn't even work in the same folder anymore. I mean, it's broken even more. It used to at least work in the same folder, now it doesn't:

    Same folder:

    upload_2020-4-23_19-15-12.png

    Different folder (UPM packages using @xoofx https://github.com/xoofx/UnityNuGet):

    upload_2020-4-23_19-21-8.jpeg

    https://issuetracker.unity3d.com/is...when-assembly-dependency-is-in-another-folder

    https://issuetracker.unity3d.com/is...assemblies-depending-on-their-place-in-assets

    https://forum.unity.com/threads/err...es-depending-on-which-folder-it-is-in.766583/
     
    Last edited: Apr 23, 2020
  23. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Yes now we do the validation and write out if the versions do not match, you need to disable the verification on the plugin to force it. Problem with relying on same folder is that any update of our Mono Runtime can have the possibility to "fix" it, so it will not work in same folder. Hopefully we have the bindingsRedirect done by then.
     
  24. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @HaraldNielsen In 2020.1b it only works unchecking "Validate References" if it's in the same folder. On different folder it doesn't work even If I uncheck "Validate References".

    It's someone working on bindingsRedirect feature? Estimated ETA?
     
  25. Bortos

    Bortos

    Joined:
    Apr 6, 2016
    Posts:
    12
    Any updates on this?
     
  26. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Yes, im currently working on a solution
     
    Per-Morten and bdovaz like this.
  27. Lars-Blaabjerg

    Lars-Blaabjerg

    Joined:
    Apr 5, 2011
    Posts:
    54
    I'm having the same issue in 2019.4.9f1. I used the workaround using the dlls in the same folder, and while I do get the following warning, it seems to work. Proper redirect bindings would be really nice though.
     
  28. disuperguy

    disuperguy

    Joined:
    Nov 6, 2019
    Posts:
    8
    its been awhile, I also have this problem, was working until it didnt.
     
  29. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Yes, only now we got to work on this issue :) Currently also finding out of possible backports ect.
     
    jashan, Bortos and bdovaz like this.
  30. Bortos

    Bortos

    Joined:
    Apr 6, 2016
    Posts:
    12
    Thanks Harald, appreciate your efforts

    I'm sure people consider this edge case but with the direction .NET is going I think Unity has to keep up to date within the dotnet ecoystem and play nicely there

    I'm afraid for you that the next step is to get a nuget package system working. A few Unity packages already provide assemblies, either Unity has to keep track of their assemblies within all their packages, which may leave their hands tied, or add nuget support so that packages and project can negotiate versions nicely.

    That would also make it better for package developers like myself. Playing with other packages and required assemblies is a nightmare at the moment. For example the ECS system brings in a different version of Newtonsfot Json, and also
    System.Runtime.CompilerServices.Unsafe. I have a package for providing microsoft extesnsions logging, and another for NLog. The introduction of the assembly in ECS broke things for me
     
    goncalo-vasconcelos and bdovaz like this.
  31. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    @Bortos I totally agree with you about this, and we are super aware of these things.
    One thing is the direction of .NET but supporting general tooling that .NET offers would be super helpful as a developer.
     
    goncalo-vasconcelos and bdovaz like this.
  32. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Fyi, a solution has landed in 2021.1 "Scripting: Add option to disable Signed Assembly version validation. (1193928)"

    Im currently looking into getting this back to 2020 as well.

    Let me know of your thoughts on the solution, or if you find any issues
     
    evgro, Bortos, bdovaz and 1 other person like this.
  33. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    As I saw you are also targeting 2019.4.x LTS as well, I'm glad you care about those of us who are "tied" to the LTS versions.
     
    HaraldNielsen likes this.
  34. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    @bdovas I can confirm this morning that we are also backporting to 2019.4 :)
     
  35. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    72
    HaraldNielsen likes this.
  36. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @HaraldNielsen I have some doubts with that "new checkbox":

    1. Would it fix the fact that dlls can be in different directories? I remember you mentioned something about a bug in Mono. This is what limits us a lot since we have converted to UPM packages and each one has its own dlls.
    2. I understand that if we check that checkbox it will still validate the absence of a dependency anyway, right?

    And finally any ETA on 2019.4.x LTS? Thanks!!!
     
  37. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    @dbovaz

    1: Yes it will fix the Mono issue. So no errors when assemblies is in separate folders.
    2: Yes there will still be validation of missing references for Plugins/dll's - now we just skip the Signed Version validation when the Checkbox is unchecked.

    Ill ping community with this here, if they have any information about 2019.4.x :)
     
    goncalo-vasconcelos and bdovaz like this.
  38. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    I see that it's finally fixed in:

    2021.1.0a2
    2020.2.2f1
    2019.4.17f1

    @HaraldNielsen I have found a small bug in the editor and if I have configured the backend scripting in IL2CPP I get the checkbox disabled because I understand that this problem does not affect IL2CPP but in the editor uses Mono. To solve it I have had to change the backend scripting to Mono, disable the checkbox and put IL2CPP back.

    Is there any way to remove this annoying warnings?

    I tried this thread but it didn't work and I have no way to check if it is reading the app.config file or not:

    https://forum.unity.com/threads/dependency-on-newtonsoft-json.814128/#post-5398014
     
  39. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    Oh yes I can see that being a problem! Will look into it. Can I get you to report a bug?
     
  40. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @HaraldNielsen Case 1307810

    What about this problem @HaraldNielsen ?? I remember that you played with app.config files and made some tests with them.
     
  41. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
  42. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    @bdovaz I see that someone in the team have taken the case. It will be fixed soon :) will keep you posted
     
  43. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    In this case I meant this:

     
  44. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    @HaraldNielsen Thanks for all your work on this issue; it has been very informative. What exactly is the location of the checkbox you described above? I don't see any checkbox referring to "Signed Version validation" in the Editor Preferences or Project Settings of my Unity 2021.3.10f1 project. I am using IL2CPP, so maybe the bug that @bdovaz mentioned above is related?

    Also, how does all of this change when importing assemblies as packages, not assets? I am using the excellent, open-source UnityNuGet tool (built by a Unity dev as I understand) to import NuGet packages as UPM packages, and seeing the same mismatched assembly version errors. Unfortunately, I can't just uncheck "Validate References" on any of the UPM-imported assemblies (is that the checkbox we're talking about?) because these assemblies aren't under Assets/ so the checkbox is disabled (and wouldn't update the project for all collaborators anyway).
     
    HaraldNielsen likes this.
  45. Rabadash8820

    Rabadash8820

    Joined:
    Aug 20, 2015
    Posts:
    94
    Ah nvm, I found the checkbox: "Project Settings > Player > Other Settings > Configuration > Assembly Version Validation (editor only)". The tooltip on this checkbox is also very nice, explaining that the option only affects resolution for Strong Named assemblies. This fixes my UPM import issue as well!
     
    HaraldNielsen likes this.
  46. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    139
    For 2022.2 we changed the version resolution, so instead of all this pain, we will create binding redirects in the runtime that will resolve to the version thats in the project.
    We can't backport it, as in some rare cases it can be a breaking change
     
    Rabadash8820 likes this.