Skip to content

Better report on location of an Activity without default constructor - #1169

Merged
jonpryor merged 1 commit into
dotnet:masterfrom
grendello:issue1151
Jan 9, 2018
Merged

jonpryor merged 1 commit into
dotnet:masterfrom
grendello:issue1151

Conversation

@grendello

Copy link
Copy Markdown
Contributor

Fixes: #1151

Each Activity must have a default constructor or it won't be possible to
instantiate it from the android manifest. Should the constructor be missing we
currently report the fact in a way that doesn't tell the developer where the
error occured. This is not very helpful.

This commit adds code to add the location of the offending source code, if
available, as well as changes the way we report the error - we no longer throw
an exception but instead define a new error code, XA4213, and report it using
the standard MSBuild logger.

location = $" at {sourceLocation.Document.Url}:{sourceLocation.StartLine}";
else
location = ".";
log.LogCodedError ("XA4213", $"The type '{t.FullName}' needs to have a public default constructor{location}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we should instead use TaskLoggingHelper.LogError(), and provide all of the arguments:

if (sourceLocation != null && sourceLocation.Document?.Url != null) {
    log.LogError (
            subcategory:      string.Empty,
            errorCode:        "XA4213",
            helpKeyword:      string.Empty,
            file:             sourceLocation.Document.Url
            lineNumber:       sourceLocation.StartLine,
            columnNumber:     sourceLocation.StartColumn,
            endLineNumber:    sourceLocation.EndLine,
            endColumnNumber:  sourceLocation.EndColumn,
            message:          $"The type '{t.FullName}' must provide a public default constructor.")
} else {
    log.LogCodedError ("XA4213", $"The type '{t.FullName}' needs to have a public default constructor");
}

Fixes: dotnet#1151

Each Activity must have a default constructor or it won't be possible to
instantiate it from the android manifest. Should the constructor be missing we
currently report the fact in a way that doesn't tell the developer where the
error occured. This is not very helpful.

This commit adds code to add the location of the offending source code, if
available, as well as changes the way we report the error - we no longer throw
an exception but instead define a new error code, XA4213, and report it using
the standard MSBuild logger.
@jonpryor
jonpryor merged commit 4c516b6 into dotnet:master Jan 9, 2018
@grendello
grendello deleted the issue1151 branch January 10, 2018 08:01
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants