Loading Assembly from file throws a FileNotFoundException

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: Injecting and Executing Code on runtime - Google Docs

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.

1 Like

It’s 22 and this still solved my problem, thanks! ;D

Then please simply hit the like button instead so you don’t necro the 6 year old post.

Thanks.

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.