Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

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

Discussion in '2017.1 Beta' started by GlitchEnzo2, Jun 4, 2017.

  1. GlitchEnzo2

    GlitchEnzo2

    Joined:
    Nov 15, 2012
    Posts:
    5
    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:
    Code (CSharp):
    1. using System.IO;
    2. using System.Linq;
    3. using System.Net;
    4. using System.ServiceModel.Syndication;
    5. using System.Xml;
    6. using UnityEngine;
    7.  
    8. public class FeedTest : MonoBehaviour
    9. {
    10.     void Start()
    11.     {
    12.         string url = "https://www.nuget.org/api/v2/FindPackagesById()?$orderby=Version asc&id='Owin'&$filter=Version ge '1.0'";
    13.  
    14.         // Mono doesn't have a Certificate Authority, so we have to provide all validation manually.  Currently just accept anything.
    15.         // See here: http://stackoverflow.com/questions/4926676/mono-webrequest-fails-with-https
    16.         ServicePointManager.ServerCertificateValidationCallback = null;
    17.         ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policyErrors) => true;
    18.  
    19.         HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(url);
    20.         getRequest.Timeout = 5000;
    21.         getRequest.ReadWriteTimeout = 5000;
    22.         Stream responseStream = getRequest.GetResponse().GetResponseStream();
    23.         SyndicationFeed feed = SyndicationFeed.Load(XmlReader.Create(responseStream));
    24.  
    25.         Debug.Log(feed.Items.First().Id);
    26.     }
    27. }
    3) Hit play and everything works fine.

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

    5) 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).
    https://msdn.microsoft.com/en-us/li...el.syndication.syndicationfeed(v=vs.110).aspx

    [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.
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,678
    The 4.6 DLLs are located at Editor\Data\MonoBleedingEdge\lib\mono\4.5.
     
  3. GlitchEnzo2

    GlitchEnzo2

    Joined:
    Nov 15, 2012
    Posts:
    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!