3

I'm building a C# class in Visual Studio 2015 CTP 6, within an ASP.NET Web Application project (it's MVC). The class needs to read RSS feeds, and according to this StackOverflow post, the best way to do this is via the System.ServiceModel.Syndication namespace.

I tried adding the DLL needed for this by right-clicking References under the web.app folder in Visual Studio's Solution Explorer. Then I selected Add Reference... In the dialog box, it didn't have any ASP.NET 5.0 libraries listed; it only had the 4.0 version of various libraries listed. So I added System.ServiceModel (4.0.0.0).

Now Visual Studio is throwing these errors:

...\src\web.app\Models\RssFeedModels.cs(4,14): ASP.NET Core 5.0 error CS0234: The type or namespace name 'ServiceModel' does not exist in the namespace 'System' (are you missing an assembly reference?)
...\src\web.app\Models\RssFeedModels.cs(21,17): ASP.NET Core 5.0 error CS0246: The type or namespace name 'SyndicationFeed' could not be found (are you missing a using directive or an assembly reference?)
...\src\web.app\Models\RssFeedModels.cs(25,20): ASP.NET Core 5.0 error CS0103: The name 'SyndicationFeed' does not exist in the current context

Here's my RssFeedModels.cs class:

using System;
using System.Collections.Generic;
using System.Xml;
using System.ServiceModel.Syndication;

namespace web.app.Models
{
    public class Rss
    {
        public string Title { get; set; }
        public string ContentSnippet { get; set; }
        public string Content { get; set; }
        public string PubDate { get; set; }
    }

    public class RssFeedModels
    {
        private XmlReader reader;
        private SyndicationFeed feed;

        public RssFeedModels(string url) {
            reader = XmlReader.Create(url);
            feed = SyndicationFeed.Load(reader);
        }
    }
}

How do I resolve this issue? Thank you.

Update: Modified the project.json file as recommended by heymega. Here's what the project.json file's pertinent section looks like:

"commands": {
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
    "gen": "Microsoft.Framework.CodeGeneration",
    "ef": "EntityFramework.Commands",
    "run": "run"
},

"frameworks": {
    "dnx451": { },
    "dnxcore50": { },
    "aspnet50": {
        "dependencies": {
            "Microsoft.AspNet.Mvc": "6.0.0-beta2"
        },
        "frameworkAssemblies": {
            "System.ServiceModel": "4.0.0.0"
        }
    }
},

This throws many errors, starting with this:

The type or namespace name 'ServiceModel' does not exist in the namespace 'System' (are you missing an assembly reference?) web.app.DNX 4.5.1
Community
  • 1
  • 1
Alex
  • 34,699
  • 13
  • 75
  • 158

1 Answers1

4

System.ServiceModel hasn't been ported to ASP.NET 5 yet so you can't use it as part of the core library.

You should be able to include the reference for a standard aspnet50 project (Not core).

{
    "commands": {
        "run": "run"
    },
    "frameworks": {
        "aspnet50": {
            "dependencies": {
                "Microsoft.AspNet.Mvc": "6.0.0-beta2"
            },
            "frameworkAssemblies": {
                "System.ServiceModel": "4.0.0.0"
            }
        }
    }
}

I asked a similar question here when trying to add a WCF service reference.

Community
  • 1
  • 1
heymega
  • 9,215
  • 8
  • 42
  • 61
  • 3
    For anyone wondering, this goes into the `project.json` file. – Alex May 15 '15 at 15:50
  • 1
    How do you modify the project.json file? It already has items in it. Do we just add this to it? Thanks – Alex May 15 '15 at 17:19
  • 1
    Yes - You manually add or remove dependencies from project.json. Visual studio watches for changes in that file and will add and remove the actual references behind the scenes. Give it a go :) – heymega May 17 '15 at 13:54
  • 1
    It throws 1167 errors when I add the above code to the `project.json` file. Please see my update to the question above. – Alex May 18 '15 at 12:20