C# NLog; Cannot find NLog.xsd file
Asked Answered
E

4

18

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?

Epexegesis answered 2/3, 2016 at 8:23 Comment(0)
E
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.

Epexegesis answered 2/3, 2016 at 8:28 Comment(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.Joelynn
J
18

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.

Joelynn answered 18/1, 2018 at 0:3 Comment(2)
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 properlyNimesh
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.Komi
E
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.

Epexegesis answered 2/3, 2016 at 8:28 Comment(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.Joelynn
D
12

This worked for me in visual studio.

  • Go to Project -> Manage NuGet Packages -> Browse for NLog.Schema
  • Install it
Discerning answered 6/8, 2020 at 5:54 Comment(1)
NuGet copies the file to <UserDir>\.nuget\packages\nlog.schema\4.7.14\contentFiles\any\any While VS looks for it in <UserDir>\source\repos\<SolutionName>\<ProjectName>Encratia
L
0

You can directly reference the latest schema by giving the full url:

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

This will work for project reference styled projects.

But it will expose you to another problem with custom targets. (NLog xsi:type not working with custom target)

Lashandralashar answered 4/6 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.