Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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

Discussion in 'Scripting' started by wavejumes, Feb 13, 2017.

  1. wavejumes

    wavejumes

    Joined:
    Feb 13, 2017
    Posts:
    6
    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 https://github.com/NLog/NLog/issues/1955
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    6,480
    It will be referenced by NLog or one of NLogs dependencies. Are you using the correct NLog.dll?
     
  3. wavejumes

    wavejumes

    Joined:
    Feb 13, 2017
    Posts:
    6
    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.
     

    Attached Files:

  4. wavejumes

    wavejumes

    Joined:
    Feb 13, 2017
    Posts:
    6
    @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<string> __visited = new HashSet<string>();

    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();
    }

    }
    }

     
  5. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    127
    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.
     
    wavejumes likes this.
  6. aidesigner

    aidesigner

    Joined:
    May 2, 2012
    Posts:
    121
    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.
     
    wavejumes likes this.
  7. LisFox7

    LisFox7

    Joined:
    May 5, 2019
    Posts:
    11
    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.
     
unityunity