Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unloading broken assembly ?.dll, this assembly can cause crashes in the runtime

Discussion in 'Experimental Scripting Previews' started by AVOlight, Feb 10, 2018.

  1. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    391
    Last edited: Feb 11, 2018
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    You may want to submit a different bug report with the assemblies or code that causes the problem in this case. I'm not sure about the specific cause for this Google.Api.Gax.Grpc code, but we can investigate.
     
    AVOlight likes this.
  3. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    391
    Thank you

    There are a lot of dependencies so I think it's best to stay away from the source and stick with nuget managing the packages.

    Also get "Loading script assembly "Assets/Plugins/System.Net.Http.dll" failed!"
    System.Net.Http (>= 4.3.1)

    when targeting android there doesn't seem to be a way to reference the version that's part of the Unity installation
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    I would recommend avoiding copying class library assemblies into the project directory. You should be able to reference them in your build with an mcs.rsp file. You can add on to the Assets/ directory of the project with these contents:

    -r:System.Net.Http.dll

    That should work properly with the .NET 4.x profile.
     
    AVOlight likes this.
  5. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    391
    @JoshPeterson Thank you it worked! :) That's very good to know

    now its just the one error
    "Unloading broken assembly Library/ScriptAssemblies/Assembly-CSharp.dll, this assembly can cause crashes in the runtime"
    instead of pointing to all the packages that are marked "broken assembly", i've just merged them into 1 using the source

    so would it be easier to solve the "Unloading broken assembly" with the source? should i submit it even though it might have different issues because of the code version downgrade
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    I don't think it would be easier one way or another. We should be able track down the cause of the problem either with source code or with an assembly.
     
    AVOlight likes this.
  7. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    391
  8. N3uRo

    N3uRo

    Joined:
    Dec 10, 2011
    Posts:
    513
    mcs.rsp can only be in root folder? Because sometimes we would want to have dependencies separated in a logical structure like modules. So we can separate that -r dependencies.
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    Yes, right now we only pick up one mcs.rsp file in the Assets folder of the project, unfortunately. This would be a nice feature though. I suspect it might be possible to aggregate all of mcs.rsp files in a project with an editor script.
     
  10. N3uRo

    N3uRo

    Joined:
    Dec 10, 2011
    Posts:
    513
    Are you then considering it?

    For example, link.xml works like that, you can have multiple files across hierarchy and they are merged together.
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    It is not something we are actively working on. We might do it in the future, but I doubt it will be soon.
     
  12. N3uRo

    N3uRo

    Joined:
    Dec 10, 2011
    Posts:
    513
    I don't understand how it will merge with nuget support that we saw in a Microsoft Youtube video when they said that it was on 2018 roadmap to get Unity VS Tools nuget support.
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    I'm not sure about that either. From the Unity side, we're not planning nuget support. Microsoft might be planning to do that from the Visual Studio side though. I would expect that Visual Studio might write a combined mcs.rsp into the Unity project in that case. But I don't have any specific knowledge about this.
     
  14. N3uRo

    N3uRo

    Joined:
    Dec 10, 2011
    Posts:
    513
    If you want more info on this:

     
  15. JaredThirsk

    JaredThirsk

    Joined:
    Jan 17, 2010
    Posts:
    38
    @JoshPeterson, is there any way for us users to determine why we are getting the "Unloading broken assembly ..., this assembly can cause crashes in the runtime"?

    I can share my code with you (an open source NetStandard2.0 DLL) if that would help but I would like to understand what breaks Unity and what doesn't, so I can know what my options are.
     
  16. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    Unfortunately, that error message is pretty opaque. I'm not even sure about all of the cases that cause it! I think it means that the assembly (or one of its dependencies) could not be loaded. If you can provide a project that reproduces the issue in a bug report, I think we can provide more details. Hopefully we can also improve the error message.
     
  17. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    594
    we are having the same issue and you can repro it easily using the .net standard (1.3) version of log4net.dll. For us it always results in

    Unloading broken assembly Assets/Assemblies/Log4Net/log4net.dll, this assembly can cause crashes in the runtime

    which it means that we cannot use .net standard 2.0 with log4net. It may be due to external dependencies log4net needs.

    @JoshPeterson It may be the same reason why IL2CPP linking was failing (if you remember what I am talking about)
     
    Last edited: Jun 7, 2018
  18. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    @sebas77

    Can you drop us a bug report, so that we have have the exact project, Unity version number, etc?
     
  19. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    594
    ok I will try to create a simple project using that dll
     
    JoshPeterson likes this.
  20. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    594
  21. RodrigoAbreu

    RodrigoAbreu

    Joined:
    Jan 29, 2013
    Posts:
    3
    The only reason why an external dll complains with "Unloading broken assembly" is because you may not have imported the dependency dlls with it.
    For example, if you try to use GraphQL and/or GraphQLParser it may start exploding the message above as a way to say that it's missing Newtonsoft.Json, the message is just not really clear, I know but but always try to check original .net (C#) project to see the dependency libraries used by it and make sure to import them as well, but only if they're not part of the standard C# libraries or if the assetstore doesn't have it yet, as in the case of Newtonsoft.Json.
     
  22. nupur7

    nupur7

    Joined:
    Feb 15, 2017
    Posts:
    6
    I m also facing the same issue unloading broken assembly..can crash at runtime
    I am trying to receive data from azure event hub to unity. .For that i have downloaded azure eventhub processor nuget package, out of which i have copied dll into asset folder but getting the error mentioned above.
    Anyone has found the solution? Thanks in advance
     
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    @nupur7

    Do you know if this DLL from nuget was compiled against .NET Core? If so, that might cause this issue, as .NET Core assemblies are not supported in Unity.
     
  24. InvarJasonPelgen

    InvarJasonPelgen

    Joined:
    Mar 7, 2018
    Posts:
    4
    I am trying to import a *.dll file to the plugins folder. I changed the runtime version to .NET 4.x and API compatibility to .NET 4.x in the editor, as my file uses .NET 4.6. But once this is all said and done, i get the error "Unloading broken assembly Assets/Plugins/Invar.Core.dll, this assembly can cause crashes in the runtime". If I'm using the proper compatibility, why is this still occurring?

    I've also tried creatign a *.txt file, renaming it to mcs.rsp and putting -r:Invar.Core.dll as my reference. and unity barks back "error CS0006: Metadata file `Invar.Core.dll' could not be found."
     
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    Unfortunately, the "Unloading broken assembly" error is a bit opaque, and does not give much information about the cause of the problem. I don't think a .rsp file is necessary in this case though.

    Do you know how your Invar.Core.dll assembly was compiled? Was it built against the .NET 4.6 Framework? If it was built against .NET Core, for example, it won't work with Unity.
     
  26. InvarJasonPelgen

    InvarJasonPelgen

    Joined:
    Mar 7, 2018
    Posts:
    4
    It was built against .NET 4.6. It's been a hair-pulling week haha! But was what I described before the correct way to reference a *.dll? I'm a newbie haha.
     
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    Can you drop it into a tool like ILSpy and look at its references? Maybe it references something that Unity does not.
     
  28. InvarJasonPelgen

    InvarJasonPelgen

    Joined:
    Mar 7, 2018
    Posts:
    4
    Ok, Target framework is v4.0. As for the references:


    using System.Diagnostics;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Runtime.Versioning;
     
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    I think these are namespaces, but not assembly references. You should see something like mscorlib.dll, System.dll, etc. In the assembly references.
     
  30. InvarJasonPelgen

    InvarJasonPelgen

    Joined:
    Mar 7, 2018
    Posts:
    4
    Apologies! didn't even notice the references folder in the left panel. Made a screen cap of the list of references.
     

    Attached Files:

  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    This is definitely built against the .NET Framework. I'm not sure about a few of the references though, most notably IronPython. I'm not sure that Unity supports that. Can you submit a bug report with this project? Maybe we can dig into that error message and get you better, more specific feedback.
     
  32. N3uRo

    N3uRo

    Joined:
    Dec 10, 2011
    Posts:
    513
    Do you have plans on giving a more descriptive error details like what assemblies are not included? When we make a build it throws a more detailed error for example.
     
  33. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,370
    We have some improvements to this error message on the way, but we still don't give full information about the cause of the assembly loading problem. That is something we plan to do in the future though.