6

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?

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
mhtsbt
  • 1,029
  • 2
  • 12
  • 26
  • Try deleting the bin folder in your project. I looks like you updated the Net library and the code didn't completely recompile. So you are getting a mixture of compiled code looking at the old and new versions of Net. Deleting the bin will force all the code to recompile and point to the same version of the library. This is a common occurrence because the dependency in the compile doesn't recognize the differences in the versions of Net. – jdweng Aug 14 '15 at 10:15

1 Answers1

7

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

Community
  • 1
  • 1
Daniel J.G.
  • 34,266
  • 9
  • 112
  • 112