16

Just for the case that somebody produces one day the same error.

In the starting section of the NLog.config file Visual Studio tells me (with a warning) that it cannot find the NLog.xsd File

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"

That is the reason why I cannot use intellisense while editing the config file. Although NLog is installed with the config section and all files are present in the project folder the error persists. Why?

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76

3 Answers3

17

I fixed the same issue by downloading the schema from "http://www.nlog-project.org/schemas/NLog.xsd" then saving it to my project directory and adding it to the project ...

  • Right click project name in solution explorer.
  • Select Add | Existing item
  • Browse to the new xsd file and select it.

Then the warnings went away.

  • 1
    Just to add. I had similar issue and it was looking for at a specific folder "C:\Users\myusername\.nuget\packages\nlog.config\4.5.6\contentFiles\any\any" I followed steps above to download file and added to the location I just listed and it worked properly – JMIII Jul 11 '18 at 18:38
  • 1
    I just ran into this issue, and this fix worked. I also wanted to add that if you are downloading the file as a ".xml" it will fail change the extension to ".xsd" and you may need to add the file manually by navigating to the file path in the warning message. – Luther Nov 14 '19 at 14:03
14

So, by hovering with the mouse over the blue underlined line of code in the NLog.config file:

xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"

I realised that Visual Studio was searching for the file 2 folders above my project folder. The solution was that the parent folder of my project folder had a "#" in its name! Thereby apparently preventing VS from finding the config file. After removing the "#" the warning disappeared and I could use intellisense again.

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
  • 1
    That's a great find! One must be careful when using uncommon characters in file paths. I try to never even use spaces in file names of paths. – Phillip H. Blanton Nov 18 '19 at 19:18
11

This worked for me in visual studio.

  • Go to Project -> Manage NuGet Packages -> Browse for NLog.Schema
  • Install it
Ankit Giri
  • 2,355
  • 2
  • 10
  • 15
  • 2
    NuGet copies the file to \.nuget\packages\nlog.schema\4.7.14\contentFiles\any\any While VS looks for it in \source\repos\\ – Avi Feb 27 '22 at 16:06