Ge Xiaohe
Ge Xiaohe
CC#
Created by Ge Xiaohe on 8/22/2023 in #help
✅ How to resolve CS9017 when trying passing captured arguments by primary constructor to base class?
Just tag the related issue here. This report exists.
https://github.com/SonarSource/sonar-dotnet/issues/7624
18 replies
CC#
Created by Ge Xiaohe on 8/22/2023 in #help
✅ How to resolve CS9017 when trying passing captured arguments by primary constructor to base class?
Got that. Thanks!
18 replies
CC#
Created by Ge Xiaohe on 8/22/2023 in #help
✅ How to resolve CS9017 when trying passing captured arguments by primary constructor to base class?
No, all codes pasted here are coded by me.
18 replies
CC#
Created by Ge Xiaohe on 8/22/2023 in #help
✅ How to resolve CS9017 when trying passing captured arguments by primary constructor to base class?
Thanks, I understand that passing to base class and referencing a parameter will result in double storage. I need to change one of them. 1. Not referencing appConfig in derived class:
// in base class
// as property:
protected IOptionsMonitor<AppConfig> AppConfig => appConfig;
// as field (SonarLint reports: Remove the member initializer, all constructors set an initial value for the member. It seems to be a misreport.):
protected readonly IOptionsMonitor<AppConfig> AppConfig = appConfig;
// which one is recommended?
// in base class
// as property:
protected IOptionsMonitor<AppConfig> AppConfig => appConfig;
// as field (SonarLint reports: Remove the member initializer, all constructors set an initial value for the member. It seems to be a misreport.):
protected readonly IOptionsMonitor<AppConfig> AppConfig = appConfig;
// which one is recommended?
2. Or not passing appConfig to base type. I am not sure if I do not pass appConfig to base type, how I can access appConfig in base type.
18 replies
CC#
Created by Ge Xiaohe on 8/22/2023 in #help
✅ How to resolve CS9017 when trying passing captured arguments by primary constructor to base class?
Oh thanks! I will try it.
18 replies
CC#
Created by Ge Xiaohe on 8/22/2023 in #help
✅ How to resolve CS9017 when trying passing captured arguments by primary constructor to base class?
I just tried to create a minimal reproducible example. I deleted all business-related fields, properties and methods.
public class DbExtensionTest(IOptionsMonitor<AppConfig> appConfig, LogExtension logger, string connectionString)
{
}

public class LocalDbExtensionTest(IOptionsMonitor<AppConfig> appConfig, LogExtension logger, string connectionString)
: DbExtensionTest(appConfig, logger, connectionString)
{
public string Demo()
{
AppConfig appConfigCurrentValue = appConfig.CurrentValue;
return $"Demo{appConfigCurrentValue}";
}
}
public class DbExtensionTest(IOptionsMonitor<AppConfig> appConfig, LogExtension logger, string connectionString)
{
}

public class LocalDbExtensionTest(IOptionsMonitor<AppConfig> appConfig, LogExtension logger, string connectionString)
: DbExtensionTest(appConfig, logger, connectionString)
{
public string Demo()
{
AppConfig appConfigCurrentValue = appConfig.CurrentValue;
return $"Demo{appConfigCurrentValue}";
}
}
Now, ignoring Warning CS9113, the warning CS9107 mentioned above happens to appConfig.
18 replies