zakparks31191
zakparks31191

Reputation: 927

"Could not load System.XML Version 2.0.5.0" exception with NLog

I'm getting an exception "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." with the stack trace "at NLog.Config.XmlLoggingConfiguration..ctor(String fileName, Boolean ignoreErrors, LogFactory logFactory) at NLog.LogFactory.LoadLoggingConfiguration(String configFile)".

What I'm not sure of, is that I have a reference to System.XML in the project, but this isn't being found? I've removed/re-added the reference and read through other questions similar to this but can't seem to get past this. Is there something NLog needs to find this reference, or a list of dependencies I can check to see what may be missing?

I'm using:
System.XML 4.0.0.0
NLog 4.0.0.0
.NET 4.6.1

Upvotes: 0

Views: 932

Answers (2)

bodie
bodie

Reputation: 91

I solved this problem by unloading the library project that references NLog in my solution. I edited the csproj file and searched for references to NLog. I found all of these in there:

<Content Include="packages\NLog.4.7.8\lib\monoandroid44\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\monoandroid44\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\net35\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\net35\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\net40-client\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\net40-client\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\net45\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\net45\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\netstandard1.3\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\netstandard1.3\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\netstandard1.5\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\netstandard1.5\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\netstandard2.0\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\netstandard2.0\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\sl4\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\sl4\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\sl5\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\sl5\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\wp8\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\wp8\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\xamarinios10\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\xamarinios10\NLog.xml" />

I had seen some posts from other devs having similar problems, but many were using Xamarin projects in their solution. This made me think maybe the problem was the content includes for the xamarin and android assemblies. I removed everything but the .net framework stuff and ended up with this list:

<Content Include="packages\NLog.4.7.8\lib\net35\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\net35\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\net40-client\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\net40-client\NLog.xml" />
<Content Include="packages\NLog.4.7.8\lib\net45\NLog.dll" />
<Content Include="packages\NLog.4.7.8\lib\net45\NLog.xml" />

Then I reloaded the project, cleaned the solution, and rebuilt it.

Problem solved!

Upvotes: 0

zakparks31191
zakparks31191

Reputation: 927

For some reason, removing all NLog references and readding it from NuGet worked, even though i tried that yesterday... Either way it seems like i've moved past this.

Upvotes: 1

Related Questions