Unable to use System.ServiceModel.Syndication.SyndicationFeed in .NET 4.6

I’ve already filed the bug as case #917766

  1. Copy System.ServiceModel.Web.dll from [Unity Install Location]\Editor\Data\Mono\lib\mono\2.0 into your project

  2. Have simple script use SyndicationFeed, such as:

using System.IO;
using System.Linq;
using System.Net;
using System.ServiceModel.Syndication;
using System.Xml;
using UnityEngine;

public class FeedTest : MonoBehaviour
{
    void Start()
    {
        string url = "https://www.nuget.org/api/v2/FindPackagesById()?$orderby=Version asc&id='Owin'&$filter=Version ge '1.0'";

        // Mono doesn't have a Certificate Authority, so we have to provide all validation manually.  Currently just accept anything.
        // See here: http://stackoverflow.com/questions/4926676/mono-webrequest-fails-with-https
        ServicePointManager.ServerCertificateValidationCallback = null;
        ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policyErrors) => true;

        HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(url);
        getRequest.Timeout = 5000;
        getRequest.ReadWriteTimeout = 5000;
        Stream responseStream = getRequest.GetResponse().GetResponseStream();
        SyndicationFeed feed = SyndicationFeed.Load(XmlReader.Create(responseStream));

        Debug.Log(feed.Items.First().Id);
    }
}
  1. Hit play and everything works fine.

  2. Switch to .NET 4.6
    Related random bug: Sometimes when switching, Unity can no longer open until the Library folder is deleted

  3. Hit Play: Exception thrown - TypeLoadException: Could not resolve type with token 01000007

Related info:
The MSDN states that SyndicationFeed was moved from System.ServiceModel.Web.dll (.NET 3.5) to System.ServiceModel.dll (.NET 4.0).

[Unity Beta Install Location]\Editor\Data\Mono\lib\mono\2.0 appears to contain the .NET 2.0/3.5 DLLs
[Unity Beta Install Location]\Editor\Data\Mono\lib\mono\unity I assumed contains the .NET 4.6 DLLs

However, neither System.ServiceModel.Web.dll nor System.ServiceModel.dll in the “unity” folder contain the SyndicationFeed type.

Thus, there appears to be no way to use SyndicationFeed when in .NET 4.6 mode.

The 4.6 DLLs are located at Editor\Data\MonoBleedingEdge\lib\mono\4.5.

Doh! I should have guessed I was just looking in the wrong folder.

I can confirm that using System.ServiceModel.dll from \Editor\Data\MonoBleedingEdge\lib\mono\4.5 works in .NET 4.6 mode.

It’s kind of annoying that folks will have to import a completely different DLL depending on what version they are targeting, but that’s .NET’s fault, not Unity’s.

Thanks for the help!