Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Unable to use System.Xml or System.Xml.Linq in crossplatform project in VS.

$
0
0

I've created a Xamarin.Forms project and am working on an Android implementation.

So the main project [Projectname] contains folders such as Helpers, Models, Services, Viewmodels but no reference section.

And [Projectname].Android contains a reference section and all needed android files.

The project I'm working on should read and parse XML files online.

I've managed to make it work in a .NET test module as an independent function.
However whenever I try to test similar code placed in the core business project code part of the application (not in [projectname].Android but the [Projectname] part that is.). The creation of any sort of objects that inherit from XmlReader fail with an error such as follows:

"Message: Test method UnitTestProjectNET.UnitTest1.TestGetSubDivisions threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified."

or

"Message: Test method UnitTestProjectNET.UnitTest1.TestLoadSubdivisionXMLData threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."

The project [Projectname].Android references both System.Xml and System.Xml.Linq.
However there is no reference section for the main project [Projectname], which is where this code runs from and no apparent way to add references to it. After trying a number of different ways to code this and double checking that both references are in fact in place for the [Projectname].android project, plus making sure I reference what code library I'm using in the code these errors still persist.

Here are two examples of XML reading code methods that both create those errors above in the project, but both work if I run them in the .NET test project:

    public void getSubDivisions()
    {
        string uri = "http://api.vateud.net/subdivisions.xml";
        XmlTextReader r = new XmlTextReader(uri);

   //...
 }



    public async void loadSubdivisionXMLData()
    {
        List<VatsimSubdivision> rawData = null;
        await Task.Factory.StartNew(delegate {
            XDocument doc = XDocument.Load("http://api.vateud.net/subdivisions.xml");
            IEnumerable<VatsimSubdivision> divisions = from d in doc.Descendants("object")
                                      select new VatsimSubdivision
                                      {
                                          code = d.Attribute("code").Value,
                                          introText = d.Attribute("introtext").Value,
                                          name = d.Attribute("name").Value,
                                          official = Convert.ToBoolean(d.Attribute("official").Value),
                                          website = d.Attribute("website").Value
                                      };
            rawData = divisions.ToList();
        });

        Console.WriteLine("XML reading complete");
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>