- Home /
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".
The error says that PresentationCore.dll cannot be found. Where in your project is it?
PresentationCore.dll is one of $$anonymous$$icrosoft's .NET libraries, so I assumed that its inclusion is somehow done automatically (as some things are in Unity). I guess that was a bit silly to assume that.
I did end up including it in my project manually, but then PresentationCore.dll required another library, named UIAutomationProvider and then that library required another one, and then that one required the library System.Deployment.dll, of which there are roughly 20 different versions on my computer. I tried most of them, but every one of them got me this error: TypeLoadException: Could not load type 'System.Runtime.ConstrainedExecution.ReliabilityContractAttribute' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, Public$$anonymous$$eyToken=b77a5c561934e089'.
I went back to the documentation for EPPlus, and it seems like they did add some $$anonymous$$ONO compilation directives, however their FAQ states that they aren't sure if its even compatible with $$anonymous$$ono...
In either case, if something is trying to access mscorelib, then I'm assu$$anonymous$$g that's calling native code, and I won't be able to do that anyways.
Well, I guess I'll keep trying, but this is starting to look like a dead end.
Answer by NextLevelLab · Jun 20, 2017 at 10:30 AM
If you have set up everything correctly so that your epplus.dll works in Editor Playmode, but doesn't in Standalone, try this: http://answers.unity3d.com/questions/378005/ioniczipdll-does-not-work-in-build.html?sort=votes
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.
Hi I'm trying to do the same. I've added the I8N*.dll to my project but still no luck. Is there anything else required?
Thanks!
I also got this to work in a build. I included:
PresentationCore.dll System.Deployment.dll system.windows.input.manipulations.dll UIAutomationProvider.dll UIAutomationTypes.dll
And the .dlls from the thread linked.
Cheers!
Interesting. Even though I don't need this library anymore, this is still useful for others who are trying to integrate the creation of .xlsx file in their games. Good to hear that you guys figured out how to get it working!
This method worked for me. I can confirm that it works on Android build along with charts and functions in Excel files created.
Answer by Dan-J-31 · Jul 01, 2015 at 07:24 AM
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.
I've skimmed through that video before, but I haven't watched it in full. While I don't understand Spanish, I can make assumptions based on what he's showing in the video.
I think the video is more of a tutorial on how to use the EPPlus library. From what I understand, he never actually compiles a standalone build of his project. He only uses the editor to create the excel files. This makes sense as I had success doing this too, the problem was actually getting a standalone build to compile.
Fair play, thought you might have seen it. Just wanted to make sure. Sorry it was of no use.