Using NLog with Unity3d

387 views
Skip to first unread message

Alexander Wallisch

unread,
Dec 5, 2014, 11:54:43 AM12/5/14
to nlog-...@googlegroups.com
Hello,

I'm attempting to use NLog in a Unity3d project targeting the Unity Web player, and having a great deal of trouble getting it to work.  When I add the .dll for NLog 3.0 to my project, I immediately get an internal compiler error in Unity:

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.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
<additional unhelpful callstack here...>

Unity uses its own custom version of Mono which is somewhat akin to .NET 3.5, although support for certain features is missing.  The above error is, in my experience, usually caused by attempting to import a .dll that was built against normal .NET and uses some piece of functionality that Unity's version of Mono doesn't support.  The error message is quite unhelpful in locating the problem, but I've narrowed it down by adding NLog.dll 3.0 to an otherwise empty project and I still get this error.  I made sure I was using the version of NLog.dll that targets .NET 3.5, (rather than 4.0 or 4.5) so that's not the issue.

Things get a little bit better with NLog 2.1. There is a build of NLog 2.1 that targets .NET 2.0, and this appears to compile and work with Unity. However, it fails to build under Visual Studio, giving me the following warnings:

The primary reference "NLog" could not be resolved because it has an indirect dependency on the framework assembly "System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v3.5,Profile=Unity Web v3.5". To resolve this problem, either remove the reference "NLog" or retarget your application to a framework version which contains System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

<several additional similar warnings regarding other indirect dependencies, including System.Windows.Forms, System.Drawing, and System.Configuration>

... followed by the almost-certainly-related error:

The type or namespace name 'NLog' could not be found (are you missing a using directive or an assembly reference?)

Since it's important to me that this project compiles cleanly under Visual Studio, this is kind of a deal-breaker.

The changelog for NLog 3.0 claims that it includes a fix for the issue Avoid NullArgumentException when running in a Unity3D application. This suggests to me that somebody, somewhere, is actually using NLog with Unity and has gotten it to work (with NLog 3.0, no less) so I don't want to give up yet. Does anybody have any ideas for anything else I could try?

Thanks for any help!

(I have already seen this post. It looks like a similar error surrounding NLog and Unity, but the problem in that post turned out to be the opposite of what I'm experiencing. The OP there was including a .dll in his project that referenced NLog without including NLog in the Unity project itself, and it looks like he resolved it by adding NLog.dll directly to his project. In my case, none of the .dlls I'm including reference NLog (yet) but I'm attempting to use it in my Unity project.)

Kim Christensen

unread,
Dec 17, 2014, 3:03:40 PM12/17/14
to nlog-...@googlegroups.com

Unfortunately I don't have experience with unity3d, meaning I have no idea what's wrong and how to fix it.

Reply all
Reply to author
Forward
0 new messages