Search Unity

Loading Assembly from file throws a FileNotFoundException

Discussion in 'Scripting' started by MarcoMeter, Sep 23, 2016.

  1. MarcoMeter

    MarcoMeter

    Joined:
    Jun 14, 2013
    Posts:
    69
    Hello everybody,

    I'm working on a solution for compiling an assembly which can be loaded and executed on run-time. The class library, which I created, cannot be loaded using System.Reflection.Assembly.Load("ABC.dll"); . It throws a FileNotFoundException. The path is correct (the file is located inside the project folder), so the problem should be dealing with missing dependencies. Pasting that dll inside the Assets folder works, but I need it on run-time. The goal is that users are supposed to add custom AIs easily to the game.

    This is how I created the dll: https://docs.google.com/document/d/1GiYCFs1ZN6cIk18UIh9GbMatXCDlzmTRJ2pz4_2j2Is/edit#

    The compiled assembly contains two MonoBehaviour classes which only log once during Start(). So far I'm trying to setup a functional prototype. Does anyone have an idea for troubleshooting this problem?


    edit: Just solved it.. Instead of using Assembly.Load() I have to use Assembly.LoadFrom().
    That looks like an intuitive way to compile certain code in order to load it on a build on run-time. So different users can develope AI inside of Unity and distribute the dlls to other users.
     
    Last edited: Sep 23, 2016
    ManuBera likes this.
  2. ManuBera

    ManuBera

    Joined:
    Aug 19, 2021
    Posts:
    70
    It's 22 and this still solved my problem, thanks! ;D
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,450
    Then please simply hit the like button instead so you don't necro the 6 year old post.

    Thanks.
     
  4. ManuBera

    ManuBera

    Joined:
    Aug 19, 2021
    Posts:
    70
    In the future I will keep that in mind, but in this case I was hoping someone would come to tell me that there is now a better solution to this problem, or explain why using Assembly.LoadFrom works and Assembly.Load doesn't (VisualStudio tells me to use Load). Sorry for the inconvenience.