mhtsbt
mhtsbt

Reputation: 1079

asp.net vnext and XDocument

I'm having a problem with the latest beta-version of .net and the Xdocument library.

My project.json looks like this:

 "dependencies": {
    "Microsoft.AspNet.Mvc": "6.0.0-beta4",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta4",
    "System.Xml.XDocument": "4.0.10-beta-23109"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini"
  },

  "frameworks": {
    "dnx451": { }   
  },

And my code like this:

var xd = XDocument.Parse(str);

But I receive the error-message:

Severity    Code    Description Project File    Line
Error   CS0433  The type 'XDocument' exists in both 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.Xml.XDocument, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' WebApplication2.DNX 4.5.1   ValuesController.cs 23

Simply trying to solve it with using System.Xml.Linq.XDocument xd = or System.Xml.XDocument xd = does not seem to be working, what else could I try?

Upvotes: 6

Views: 2133

Answers (1)

Daniel J.G.
Daniel J.G.

Reputation: 34992

I have solved this by adding the System.Xml.XDocument dependency as a framework assembly (which means the one from the GAC installed with the full .Net version will be used) for the dnx451 framework and only as a nuget package for the dnxcore framework:

"frameworks": {
  "dnx451": {
    "frameworkAssemblies": { "System.Xml.Linq": "4.0.0.0" }
  },
  "dnxcore50": {
    "dependencies": { "System.Xml.XDocument": "4.0.10" }
  }
}

I think otherwise when compiling the dnx451 version it gets confused between the nuget package and the dll installed with the full .Net framework

Upvotes: 7

Related Questions