Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Xml.ReaderWriter, Version = 4.1.0.0, ... The system cannot find the file specified #429

Closed
mauricio-bv opened this issue Jul 20, 2017 · 6 comments

Comments

@mauricio-bv
Copy link

mauricio-bv commented Jul 20, 2017

  1. I created a .Net Standard Project.

  2. When trying to use the 'XmlNodeType" enumeration the program crashes with the error below:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Xml.ReaderWriter, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

A simple application that reproduces the issue can be find in the following GitHub repository:
(https://github.com/mauricio-bv/Public.git)
The application is: "XmlReadWriterError"

Link to the github code:
(https://github.com/mauricio-bv/Public/tree/master/XmlReadWriterError)

Below the code of the failing class:

using System;
using System.Diagnostics;
using System.Xml;
using System.Xml.Linq;
namespace XmlDotNetSandardClass
{
    public class DotNetStandardClass
    {
        XDocument doc = new XDocument(
              new XComment("This is a comment"),
              new XElement("Root",
                  new XElement("Child1", "data1"),
                  new XElement("Child2", "data2"),
                  new XElement("Child3", "data3")
              )
          );
        public void MethodThatFails()
        {
            foreach (XNode n in doc.Nodes())
            {
                if (n.NodeType == XmlNodeType.Element)
                {
                    Debug.WriteLine(n.ToString());
                    break;
                }
            }
        }
        public void MethodDoesNotFail()
        {
            XDocument doc = new XDocument(
               new XComment("This is a comment"),
               new XElement("Root",
                   new XElement("Child1", "data1"),
                   new XElement("Child2", "data2"),
                   new XElement("Child3", "data3")
               )
           );
            foreach (XNode n in doc.Nodes())
            {
                // This method does not fail
                //if (n.NodeType == XmlNodeType.Element)
                //{
                Debug.WriteLine(n.ToString());
                break;
                //}
            }
        }
    }
}

@mauricio-bv
Copy link
Author

Anyone on this one please?

@joperezr
Copy link
Member

Which platform are you trying to run this on? .NET Core? Desktop?

.NET Standard is just a reference assembly with no implementation that will serve only for compile time, but depending on where do you want to run it you might be missing a package.

@mauricio-bv
Copy link
Author

Hi Jose
I am targeting .NET 6.2.1. I tried other .NET versions with the same result. See my example in GtiHub:

https://github.com/mauricio-bv/Public.git
application: "XmlReadWriterError

Link to the code:
https://github.com/mauricio-bv/Public/tree/master/XmlReadWriterError

@joperezr
Copy link
Member

Can you try adding a reference to NETStandard.Library.NETFramework to your project?

@mauricio-bv
Copy link
Author

Adding the NetStandard.Library NuGet package works. Also, instead of adding the NuGet package, I added a reference to the \packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll file and it also worked.

Why do I need to ad a .Net Standard reference to my .NET Desktop application? Doesn't the .Net Desktop Framework implement everything that is in the .Net Standard? It doesn't make sense to me that the consumer of a .NetStandard targeted assembly has to reference .NetStandard dlls.

@weshaggard
Copy link
Member

@mauricio-bv it is a bug in the tooling. See dotnet/sdk#901 which also has other recommended workarounds.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants