How do you integrate the EPPlus library into Unity?

I’m running into issues integrating the library called EPPlus into my Unity project. I rely on this library to create .xlsx files that organize a bunch of data gathered from a play session once the game has finished running.

Initially, when I added the .dll to my project, I received an error that looked like this:

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

I did some searching, and found that going to the player settings and setting the configuration option “API compatibility level” to ‘.NET 2.0’ instead of ‘.NET 2.0 subset’ fixed this issue. This was great and all, and I proceeded to use the library with great joy. It spit out .xlsx files exactly how I wanted it to, and everything was going fine. Except there is one catch: this only works in the editor.

As soon as I started to compile a standalone build, I ran into more issues. The 2 error messages I received are as follows:

ArgumentException: The Assembly PresentationCore is referenced by EPPlus. But the dll is not allowed to be included or could not be found.

Error building Player: Extracting referenced dlls failed.

This is where I am stumped. I did research on what is allowed/not allowed in the Unity engine when it comes importing external code, but everything seems like it should work. Unfortunately, it does not. I was wondering if anyone here has any insight as to why this library would not function well with Unity.

Some more information about the issue:

  • I have a free version of Unity, and the current version is 4.5.2
  • EPPlus.dll is a managed library and it does not use native code (AFAIK), so Unity Pro and [DLLImport] functionality is not required.
  • EPPlus.dll is compatible with .Net Framework 3.5, which I believe is the last version that MonoDevelop supports.
  • The EPPlus.dll currently resides in the Assets/Libraries path in my project, but I have also tried Assets/Plugins to no effect. In fact, it doesn’t really matter where I put it as long as it is in the Assets folder and not in a folder named “Editor”.

If you have set up everything correctly so that your epplus.dll works in Editor Playmode, but doesn’t in Standalone, try this: ionic.zip.dll does not work in build - Unity Answers

Importing those additional .Dlls solved the issue in my case (I had the same problem that EPPlus didn’t work in Standalone)

SO: EPPlus DOES work in Unity.

Forgot to update this question. It seems like the EPPlus library is indeed compatible with Mono, but it is not compatible with Unity. Unity intentionally, and seemingly arbitrarily, prevents you against linking with particular libraries in the .NET framework, and this is the core of the issue.

I think the reasoning behind this was to prevent your project from linking with platform specific libraries (due to Unity being multi-platform and all). I don’t know if that is the actual reason, but that is my guess.

So in summary: no, the EPPlus library will not work in Unity.