System.Windows.Forms.dll assembly not referenced by my code is packed

Hello!
I got some issues when using NLog with Unity3d. I create an new empty 2d project, put NLog.dll under Assets\Plugins. Then I build Android package, I got this warning: System.Windows.Forms.dll assembly is referenced by user code, but is not supported on Android platform. Various failures might follow. UnityEditor.HostView:OnGUI() I dont know the unity3d’s packing rules. Why unity3d packes unused assembly even it is not referenced by NLog?

unity3d version: 5.6.0b3 NLog: 5.0.0(dotnet35), 4.4.2(dotnet35)

See more Why NLog references System.Windows.Forms.dll? · Issue #1955 · NLog/NLog · GitHub

It will be referenced by NLog or one of NLogs dependencies. Are you using the correct NLog.dll?

Hello, the NLog.dll’s version is 4.4.2 and 5.5.0 for .net3.5.
I use NDepend and Reflector to find dependencies, there is no System.Windows.Forms.dll referenced by NLog ans it’s dependencies.
Attachment is my empty project with NLog.

2958795--219589--cap.PNG
2958795–219590–New Unity Project.7z (2.62 MB)

@Unity Technologies
I found that log4net for .net 4.5 will be packed with Windows.Forms, but the .net 2.0 will not.
I wrote a simple dependency walker below, the out is the same.
So, how the dependency reslover works?
using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
namespace DP
{
class Program
{
static HashSet __visited = new HashSet();
static void ListAllReferencedAssembly(Assembly a, int depth, StreamWriter sw)
{
foreach (var ra in a.GetReferencedAssemblies())
{
for (int i = 0; i < depth; i++)
{
Console.Write(" ");
sw.Write(" ");
}
Console.WriteLine(ra.Name);
sw.WriteLine(ra.Name);
if (__visited.Contains(ra.Name))
continue;
__visited.Add(ra.Name);
ListAllReferencedAssembly(Assembly.Load(ra), depth + 1, sw);
}
}
static void Main(string[ ] args)
{
var dllFile = “C:\path\log4net.dll”;
var dllDpFile = dllFile + “.dp.txt”;
var a = Assembly.LoadFile(dllFile);
using (StreamWriter file = new StreamWriter(dllDpFile, false))
ListAllReferencedAssembly(a, 1, file);
Console.WriteLine(“Press any key to exit.”);
Console.Read();
}
}
}

Hello,

Just letting others who encountered this warrining know, it’s due to the fact that NLog references “System.ServiceModel”.

The reference chain for this dll is the following:

NLog → System.ServiceModel → System.Messaging → System.Windows.Forms

As you can see there is a dependency on Forms dll, due to the fact that the ServiceModel is referenced by NLog. It’s kind of pita I do agree.

Any other assembly referencing ServiceModel will be on the same boat, for example protobuf-net suffers from the same issue.

1 Like

I successfully created an asset that ported NLog to Unity, so I am familiar with the problem. In the port to Unity there is a lot of code that can be remove like Silverlight and WCF functionality. For example you can eliminated the LogReceiverService directory (References System.ServiceModel) and related targets (i.e. WCF client). A good port of NLog really needs to eliminate extraneous targets in favor of some new ones that directly apply to Unity (i.e. Unity editor console and in-game Console). There are many other items that should be addressed in a port as I mentioned in this post .

1 Like

I use WCF include in the project System.ServiceModel.dll, not used in android.
Show Error:
System.Windows.Forms.dll assembly is referenced by user code, but is not supported on Android platform. Various failures might follow.