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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity is using files loaded by Assembly.LoadFrom even after the game simulation is terminated

Discussion in 'Editor & General Support' started by SamTebbs33, May 28, 2016.

  1. SamTebbs33

    SamTebbs33

    Joined:
    Aug 24, 2014
    Posts:
    1
    I have a game that loads .dll files into the runtime with Assembly.LoadFrom(). When I have terminated the game simulation in the editor, Unity is still using these files as I can't delete, rename or move them. Is there a way of stopping this from happening?

    Dll loading code:

    foreach (var file in dir.GetFiles())
    if (file.Name.EndsWith (".dll"))
    Assembly ass = Assembly.LoadFrom (file.FullName);
     
  2. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Based on this page: https://msdn.microsoft.com/en-us/library/mt632258.aspx
    it seems that you need to load your assemblies into a custom AppDomain and then unload the AppDomain.
    I don't know if this will work in Unity, but it is worth a try.
    I suggest calling the unload code from some OnDestroy() or OnDisable() function
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    As far as i know, Unity is already loading all scripting assemblies into a custom "scripting" app domain that gets unloaded as you exit play mode.