Type A Exists in both 'B' and 'C' Conflict When Building .NET UWP Project 2018.3

I’m having issues with a Unity project that was just recently migrated from 5.6.

Specifically, the following line of code

System.Net.Dns.BeginGetHostAddresses(this.path, this.ConnectingCallback_GetEndpoint, this.connectionSessionId);

gives this error:
Error CS0433 The type ‘Dns’ exists in both ‘System.Net.NameResolution, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ and ‘WinRTLegacy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ Assembly-CSharp

I’ve noticed that this only seems to occur when I have “Unity C# Projects” selected under the Build Settings for Debugging. Any thoughts on why this might be the case? As a side note, I briefly migrated to 2017 before going to 2018 and I don’t think I saw this error there.

1 Like

Which Unity version are you on? This is weird indeed. It’s likely we introduced it in 2018.3.6f1 when we bumped the Universal Windows Platform version in generated VS project. You can probably work around it by editing project.json and changing it back to 5.0.0.

That didn’t seem to help. I changed every project.json in the build from 5.4.4 to 5.0.0 and I don’t see any change.

I’m currently on Unity 2018.3.11f1. I’ll install an older release and see if I still get this issue.

Ok, I reverted to 2018.3.5f1 and the error has disappeared. Very peculiar indeed.

EDIT I went ahead and changed the project.json UWP version on the working copy from 5.0.0 to 5.4.4 and it broke just like before. So yes, I think that must have been the reason (not sure why I couldn’t get it working that way before though).

Can we get a bug report on this?

I’m submitting one now. And FYI, on 2018.3.11f1 reverting to UWP 5.0.0 did work, I just had to restart Visual Studio, cleaning and rebuilding the solution was insufficient.

Thank you!

The fix for this landed in Unity 2018.4.1f1 (which is going to be out soon).

I upgraded my project to 2018.4.5f1 and I’m having this exact problem. Dns and IPHostEntry.
error CS0433: The type ‘IPHostEntry’ exists in both ‘System.Net.NameResolution, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ and ‘WinRTLegacy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’

error CS0433: The type ‘Dns’ exists in both ‘System.Net.NameResolution, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ and ‘WinRTLegacy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’

Are you getting these errors in Visual Studio or Unity editor? What’s your minimum SDK target version is set to?

If I open the script via Unity editor and write the code relating to that stuff, it actually works when I play in editor (no errors and functions correctly). But if I open the Visual Studio solution compiled for the UWP project it underlines it red and takes issue, or if I build to run in Visual Studio I get build errors that I pasted above.

What’s your minimum SDK target version is set to?

Minimum platform version 10.0.10240.0, Target SDK version 10.0.18362.0

I just tried this and it works for me…

Can you double check that you’re actually on 2018.4.5f1? Secondly, can you check if this happens if you build to an empty folder?

If you still run into this, could you paste exact code that triggers it or report a bug?

I created a blank 2018.4.5f1 project and tried setting it up with the same build settings that I’m using for my other UWP project. This time it said “Dns does not contain a definition for ‘GetHostEntry’” and GetHostName when building. It still works when just editing the script and then running in editor. Someone said on this Stack Overflow question that System.Net.Dns is not available in the .net framework for windows runtime (c# system.net.dns universal app (W10) not working - Stack Overflow) so maybe the problem is that I’m doing .NET for the scripting backend rather than IL2CPP (which isn’t an option for my case). I’ll look at alternatives if this is indeed the issue.

Here’s the code anyway

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using TMPro;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;

public class NetworkHUD : MonoBehaviour
{

    string localIP = "";
    private NetworkManager manager;
    void Awake()
    {

        manager = GetComponent<NetworkManager>();
        //Problem section:
        IPHostEntry host;

        host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (IPAddress ip in host.AddressList)
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                localIP = ip.ToString();
                break;
            }
        }

        Debug.Log("LocalIP: " + localIP);
    }
}

Yeah, that’s expected. .NET scripting backend only contains “BeginGetHostEntry” and “EndGetHostEntry” methods.