Skip to content

SA0001 : CoreParser : An exception occurred while parsing the file #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
volmart opened this issue Jan 7, 2016 · 4 comments
Open
Assignees

Comments

@volmart
Copy link

volmart commented Jan 7, 2016

Hi,

When I replaced v4.7.49 with Visual-StyleCop.MSBuild 4.7.58.3 from https://www.nuget.org/packages/Visual-StyleCop.MSBuild

I started to have following exception on some specific file:

...cs(1,1): error : SA0001 : CoreParser : An exception occurred while parsing the file: System.FormatException, Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
.cs(1,1): error : at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
.cs(1,1): error : at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
.cs(1,1): error : at System.String.Format(IFormatProvider provider, String format, Object[] args)
.cs(1,1): error : at StyleCop.StyleCopThread.RunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable1 analyzers) .cs(1,1): error : at StyleCop.StyleCopThread.TestAndRunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable1 analyzers, Int32 passNumber)
.cs(1,1): error : at StyleCop.StyleCopThread.ParseAndAnalyzeDocument(SourceCode sourceCode, DocumentAnalysisStatus documentStatus)
.cs(1,1): error : at StyleCop.StyleCopThread.DoWork(Object sender).

Same with Visual-StyleCop... 4.7.54

@tpacri
Copy link

tpacri commented Jan 27, 2016

Hi,

any updates/fixes for the above issue? Happens to me too. Currently working in a huge project and we tried upgrading from StyleCop.MsBuild to Visual-StyleCop.MSBuild 4.7.58.3 hoping to get support for new features in C#6, and now StyleCop crashes as seen below:

filename.cs(1,1): error : SA0001 : CoreParser : An exception occurred while parsing the file: System.FormatException, Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
filename.cs(1,1): error : at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
filename.cs(1,1): error : at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
filename.cs(1,1): error : at System.String.Format(IFormatProvider provider, String format, Object[] args)
filename.cs(1,1): error : at StyleCop.StyleCopThread.RunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable1 analyzers) filename.cs(1,1): error : at StyleCop.StyleCopThread.TestAndRunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable1 analyzers, Int32 passNumber)
filename.cs(1,1): error : at StyleCop.StyleCopThread.ParseAndAnalyzeDocument(SourceCode sourceCode, DocumentAnalysisStatus documentStatus)
filename.cs(1,1): error : at StyleCop.StyleCopThread.DoWork(Object sender).

@tpacri
Copy link

tpacri commented Jan 28, 2016

I managed to workaround the crash mentioned above, so, I will provide here the source of the issues maybe someone will have time to fix them:

#1 "string []" has to be replaced with "string[]" (no space allowed between "string" and "[]". I didn't checked if happens for other types also or only for string arrays.

#2 I had to replace this:
t => new {Query = t.Query.BuildQuery(), t.Alias, IsTable = IsTable(t.Query)}));

with this:

t =>
new
{
Query = t.Query.BuildQuery(),
Alias = t.Alias,
IsTable = IsTable(t.Query)
}).

(above code is same, only that is formatted on multiline; issue was reported as syntax error for some reason instead of formatting issue.

#3
x = reader["syspart"] as int? ?? 0;

Had to be replaced with (explicit paranthesys):

x = (reader["syspart"] as int?) ?? 0;

That's about all for our project.

Thanks in advance for those who will fix these :) !

@bgrainger
Copy link

There is an error on line 415 of StyleCopThread.cs:

details.AppendLine(string.Format(CultureInfo.CurrentCulture, "Exception message : {0}"));

string.Format is called with a {0} placeholder in the message, but without a value for the placeholder.

This prevents the original exception from being shown to the user, so it's unclear how to diagnose the underlying StyleCop error.

@efrainsteinbach
Copy link

In my case it was caused by a variable named '_' (in a using (...) statement)

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

No branches or pull requests

5 participants