2

Resolved

Error when linking CustomDictionary with relative path

description

In the newest update of StyleCop issue with relative paths was fixed

fix for 7435 - if relative dictionary path the check relative to current settings file

However when I try to add relative path to the configuration I get SA0001 error
Warning 6   SA0001 : CoreParser : An exception occurred while parsing the file: System.NullReferenceException, Object reference not set to an instance of an object.
   at StyleCop.Utils.MakeAbsolutePath(String rootFolder, String relativePath)
   at StyleCop.CSharp.DocumentationRules.AnalyzeDocument(CodeDocument document)
   at StyleCop.StyleCopThread.RunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable`1 analyzers)
   at StyleCop.StyleCopThread.TestAndRunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable`1 analyzers, Int32 passNumber)
   at StyleCop.StyleCopThread.ParseAndAnalyzeDocument(SourceCode sourceCode, DocumentAnalysisStatus documentStatus)
   at StyleCop.StyleCopThread.DoWork(Object sender).    K:\some\path    1   1   someclass
I tried different test scenarios, where settings file was included in the project, or when it was on the Top location, in all cases I get the exception presented above.

My configuration file part responsible for custom dictionary:
  <GlobalSettings>
    <CollectionProperty Name="DictionaryFolders">
      <Value>..\my\relative\path</Value>
    </CollectionProperty>
  </GlobalSettings>

comments

marinovdh wrote Sep 23, 2013 at 12:24 PM

Some problem here. I installed version 4.7.46.0 today and I received the exact same error with this Custom Dictionary:
  <GlobalSettings>
    <CollectionProperty Name="DictionaryFolders">
      <Value>.\</Value>
    </CollectionProperty>
  </GlobalSettings>

andyr wrote Sep 23, 2013 at 4:21 PM

Fixed in 4.7.47.0

Ralf_Koban wrote Oct 10, 2013 at 11:54 AM

Seems that I have a similar problem.
Is there any plan when 4.7.47.0 gets released?

Tallek wrote Dec 4, 2013 at 1:51 PM

I've just installed the 4.7.47.0 release and have been trying to get this working with no luck.

Our project structure looks something like this:
Src
---Settings.StyleCop
---CustomDictionaries
------CustomDictionary.xml
---Misc nested folders containing projects

What I am trying to do is specify in the settings file that custom dictionaries are located at ".\CustomDictionaries" with the path being relative to the settings file we have checked in to source control under the "Src" directory. I have not been successful in getting this working though.

I did a little digging, and here is what I'm seeing:
// Check relative to the settings file
string location = document.SourceCode.Settings.Location;
if (location != null)
{
    namingService.AddDictionaryFolder(
    StyleCop.Utils.MakeAbsolutePath(Path.GetDirectoryName(location), dictionaryFolder));
}
The problem appears to be that the "Location" property of the settings object is null. It looks like this may be due to the fact that the settings file being used is the merged settings object and the location property is never set.

msaladin wrote Jan 13 at 2:19 PM

This ticket seems not to be resolved (although it contains a green icon with the label resolved beneath it). I get the same problem with StyleCop 4.7.48:
Warning 1   SA0001 : CoreParser : An exception occurred while parsing the file: System.NullReferenceException, Object reference not set to an instance of an object.
   at StyleCop.Utils.MakeAbsolutePath(String rootFolder, String relativePath)
   at StyleCop.CSharp.DocumentationRules.AnalyzeDocument(CodeDocument document)
   at StyleCop.StyleCopThread.RunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable`1 analyzers)
   at StyleCop.StyleCopThread.TestAndRunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable`1 analyzers, Int32 passNumber)
   at StyleCop.StyleCopThread.ParseAndAnalyzeDocument(SourceCode sourceCode, DocumentAnalysisStatus documentStatus)
   at StyleCop.StyleCopThread.DoWork(Object sender).    C:\data\roche-rfid\src\Properties\AssemblyInfo.Solution.cs  1   1   RfidLib
Any ideas how to prevent this from happening?

IMHO this is just basic, and I am a little bit disappointed. I keep spending my time with such basic stuff, and it look that no StyleCop developer cares about how usable your software is (last entry in this thread is 4. december 2013).

I keep getting Spelling Errors because it does not find my CustomDictionary.xml, and the absolute path is working fine but is not applicable when several developers work on the same project. So a solution seem not really too far fetched, but I am out of ideas how to make a workaround for a seemly simple solution in the source code?

To more specific:
  • When I have no entry "DictionaryFolders" in StyleCop.Settings, StyleCop returns spelling errors (ignoring my custom dictionary).
  • When I insert the absolute path to the CustomDictionary.xml dir in StyleCop.Settings, StyleCop returns NO errors.
  • When I remove the absolute path from StyleCop.Settings (no DictionaryFolders at all), but when I had the absolute path in it from before, StyleCop returns NO errors. Somehow, the absolute path seems to be cached to make it extra hard to find out what is going on.
  • After a new reboot, I (again) keep getting the spelling errors.
Any help (by a committer of StyleCop, or by anybody) would be greatly appreciated.
Thanks a lot.
Michael