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.
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.
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).
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.
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’
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.
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);
}
}