Skip to content
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

Logger Generator not able to Resolve Generic Type Constraints #62026

Closed
matthawley opened this issue Nov 24, 2021 · 2 comments
Closed

Logger Generator not able to Resolve Generic Type Constraints #62026

matthawley opened this issue Nov 24, 2021 · 2 comments
Labels
area-Extensions-Logging untriaged New issue has not been triaged by the area owner

Comments

@matthawley
Copy link

Description

When using the logger generator on an abstract class that defines a type constraint that is outside of the current scope, it will not compile correctly.

Reproduction Steps

internal abstract partial class AzureHandlerBase<TRequirement> : AuthorizationHandler<TRequirement> 
        where TRequirement : IAuthorizationRequirement
{
    private readonly ILogger _logger;

    protected AzureHandlerBase(ILogger logger) {
        _logger = logger;
    }

    [LoggerMessage(1, LogLevel.Information, "Test")]
    private partial void LogIt();
}

Expected behavior

The generated source code would allow the project to compile cleanly.

Actual behavior

The errors produced are the following:

error CS0246: The type or namespace name 'IAuthorizationRequirement' could not be found (are you missing a using directive or an assembly reference?)
error CS0265: Partial declarations of 'AzureHandlerBase<TRequirement>' have inconsistent constraints for type parameter 'TRequirement'

Regression?

Not that I'm aware of.

Known Workarounds

Fully referencing the type constraint with namespaces allows it to compile:

internal abstract partial class AzureHandlerBase<TRequirement> : AuthorizationHandler<TRequirement> 
        where TRequirement : Microsoft.AspNetCore.Authorization.IAuthorizationRequirement
{
    private readonly ILogger _logger;

    protected AzureHandlerBase(ILogger logger) {
        _logger = logger;
    }

    [LoggerMessage(1, LogLevel.Information, "Test")]
    private partial void LogIt();
}

Configuration

.NET 6
Windows 11

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added area-Extensions-Logging untriaged New issue has not been triaged by the area owner labels Nov 24, 2021
@ghost
Copy link

ghost commented Nov 24, 2021

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

When using the logger generator on an abstract class that defines a type constraint that is outside of the current scope, it will not compile correctly.

Reproduction Steps

internal abstract partial class AzureHandlerBase<TRequirement> : AuthorizationHandler<TRequirement> 
        where TRequirement : IAuthorizationRequirement
{
    private readonly ILogger _logger;

    protected AzureHandlerBase(ILogger logger) {
        _logger = logger;
    }

    [LoggerMessage(1, LogLevel.Information, "Test")]
    private partial void LogIt();
}

Expected behavior

The generated source code would allow the project to compile cleanly.

Actual behavior

The errors produced are the following:

error CS0246: The type or namespace name 'IAuthorizationRequirement' could not be found (are you missing a using directive or an assembly reference?)
error CS0265: Partial declarations of 'AzureHandlerBase<TRequirement>' have inconsistent constraints for type parameter 'TRequirement'

Regression?

Not that I'm aware of.

Known Workarounds

Fully referencing the type constraint with namespaces allows it to compile:

internal abstract partial class AzureHandlerBase<TRequirement> : AuthorizationHandler<TRequirement> 
        where TRequirement : Microsoft.AspNetCore.Authorization.IAuthorizationRequirement
{
    private readonly ILogger _logger;

    protected AzureHandlerBase(ILogger logger) {
        _logger = logger;
    }

    [LoggerMessage(1, LogLevel.Information, "Test")]
    private partial void LogIt();
}

Configuration

.NET 6
Windows 11

Other information

No response

Author: matthawley
Assignees: -
Labels:

untriaged, area-Extensions-Logging

Milestone: -

@martincostello
Copy link
Member

Possible dupe of #58550.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Logging untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants