Примеры ошибок, обнаруженных с помощью диагностики V3105
V3105. The 'a' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible.
Microsoft Bot Builder
V3105 The 'parts' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. JwtTokenExtractor.cs 60
public async Task<ClaimsIdentity>
GetIdentityAsync(string authorizationHeader)
{
....
string[] parts = authorizationHeader?.Split(' ');
if (parts.Length == 2) // <=
return await GetIdentityAsync(parts[0], parts[1]).
ConfigureAwait(false);
....
}
.NET Core Libraries (CoreFX)
V3105 The 'versionString' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. RuntimeInformation.cs 29
public static string FrameworkDescription
{
get
{
if (s_frameworkDescription == null)
{
string versionString = (string)AppContext.GetData("FX_PRODUCT_VERSION");
if (versionString == null)
{
....
versionString
= typeof(object).Assembly
.GetCustomAttribute<
AssemblyInformationalVersionAttribute>()
?.InformationalVersion; // <=
....
int plusIndex = versionString.IndexOf('+'); // <=
....
}
....
}
....
}
}
ML.NET
V3105 The 'mdType' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. PipelineEnsemble.cs 670
private static int CheckKeyLabelColumnCore<T>(....) where T : ....
{
....
for (int i = 1; i < models.Length; i++)
{
....
var mdType = labelCol.Annotations
.Schema
.GetColumnOrNull(....)? // <=
.Type;
if (!mdType.Equals(keyValuesType))
throw env.Except(....);
....
}
....
}
ILSpy
V3105 The 'm' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. ILSpy MethodVirtualUsedByAnalyzer.cs 137
static bool ScanMethodBody(IMethod analyzedMethod,
IMethod method, MethodBodyBlock methodBody)
{
....
var mainModule = (MetadataModule)method.ParentModule;
....
switch (member.Kind)
{
case HandleKind.MethodDefinition:
case HandleKind.MethodSpecification:
case HandleKind.MemberReference:
var m = (mainModule.ResolveEntity(member, genericContext) as IMember)
?.MemberDefinition;
if ( m.MetadataToken == analyzedMethod.MetadataToken // <=
&& m.ParentModule.PEFile == analyzedMethod.ParentModule.PEFile) // <=
{
return true;
}
break;
}
....
}
RavenDB
V3105 The 'newInternalDestinations' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. ReplicationLoader.cs 828
private void HandleInternalReplication(DatabaseRecord newRecord,
List<IDisposable> instancesToDispose)
{
var newInternalDestinations = newRecord.Topology?.GetDestinations(....);
....
foreach (var item in newInternalDestinations)
....
}
Ryujinx
V3105 The 'result' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. Client.cs 213
private byte[] Receive(int clientId, int timeout = 0)
{
....
var result = _client?.Receive(ref endPoint);
if (result.Length > 0)
{
....
}
....
}
PeachPie
V3105 The 'tinfo' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. Objects.cs 189
public static string get_parent_class(....)
{
if (caller.Equals(default))
{
return null;
}
var tinfo = Type.GetTypeFromHandle(caller)?.GetPhpTypeInfo();
return tinfo.BaseType?.Name;
}
Umbraco
V3105 The 'routeEndpoints' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. RoutableDocumentFilter.cs 198
private bool MatchesEndpoint(string absPath)
{
IEnumerable<RouteEndpoint> routeEndpoints = _endpointDataSource
?.Endpoints
.OfType<RouteEndpoint>()
.Where(x =>
{
....
});
var routeValues = new RouteValueDictionary();
RouteEndpoint matchedEndpoint = routeEndpoints
.Where(e => new TemplateMatcher(
TemplateParser.Parse(e.RoutePattern.RawText),
new RouteValueDictionary())
.TryMatch(absPath, routeValues))
.OrderBy(c => c.Order)
.FirstOrDefault();
return matchedEndpoint != null;
}
Eto.Forms
V3105 The 'fontDesc' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. Eto.Gtk3 RichTextAreaHandler.cs 328
public Font SelectionFont
{
get
{
....
Pango.FontDescription fontDesc = null;
....
foreach (var face in family.Faces)
{
var faceDesc = face.Describe();
if ( faceDesc.Weight == weight
&& faceDesc.Style == style
&& faceDesc.Stretch == stretch)
{
fontDesc = faceDesc;
break;
}
}
if (fontDesc == null)
fontDesc = family.Faces[0]?.Describe(); // <=
var fontSizeTag = GetTag(FontSizePrefix);
fontDesc.Size = fontSizeTag != null // <=
? fontSizeTag.Size
: (int)(Font.Size * Pango.Scale.PangoScale);
....
}
}
Bitwarden
V3105 The '_billingSettings' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. FreshdeskController.cs 47
public class FreshdeskController : Controller
{
....
public FreshdeskController(
IUserRepository userRepository,
IOrganizationRepository organizationRepository,
IOrganizationUserRepository organizationUserRepository,
IOptions<BillingSettings> billingSettings,
ILogger<AppleController> logger,
GlobalSettings globalSettings)
{
_billingSettings = billingSettings?.Value; // <=
_userRepository = userRepository;
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
_logger = logger;
_globalSettings = globalSettings;
_freshdeskAuthkey = Convert.ToBase64String(
Encoding.UTF8
.GetBytes($"{_billingSettings.FreshdeskApiKey}:X")); // <=
}
....
}
Bitwarden
V3105 The 'bSettings' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. PayPalIpnClient.cs 22
public PayPalIpnClient(IOptions<BillingSettings> billingSettings)
{
var bSettings = billingSettings?.Value;
_ipnUri = new Uri(bSettings.PayPal.Production ?
"https://www.paypal.com/cgi-bin/webscr" :
"https://www.sandbox.paypal.com/cgi-bin/webscr");
}
AvalonStudio
V3105 The 'mouseDevice' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. TooltipBehavior.cs 173
private async void Timer_Tick(object sender, EventArgs e)
{
....
if (AssociatedObject.IsPointerOver)
{
var mouseDevice = (popup.GetVisualRoot() as IInputRoot)?.MouseDevice;
lastPoint = mouseDevice.GetPosition(AssociatedObject);
popup.Open();
}
}
AvalonStudio
V3105 The 'languageServiceProvider' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. CodeEditorViewModel.cs 309
private void RegisterLanguageService(ISourceFile sourceFile)
{
....
var languageServiceProvider = IoC.Get<IStudio>()
.LanguageServiceProviders
.FirstOrDefault(....)?.Value;
LanguageService = languageServiceProvider.CreateLanguageService(); // <=
if (LanguageService != null)
{
....
}
}
OrchardCore
V3105 The 'lastProviders' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. ShellSettingsManager.cs 242
private async Task EnsureConfigurationAsync()
{
....
var lastProviders = (_applicationConfiguration as IConfigurationRoot)
?.Providers.Where(p =>
p is EnvironmentVariablesConfigurationProvider ||
p is CommandLineConfigurationProvider).ToArray();
....
if (lastProviders.Count() > 0)
{
....
}
....
}
OrchardCore
V3105 The 'externalClaims' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. AccountController.cs 786
private async Task<string> GenerateUsername(ExternalLoginInfo info)
{
....
var externalClaims = info?.Principal.GetSerializableClaims();
....
foreach (var item in _externalLoginHandlers)
{
try
{
var userName = await item.GenerateUserName(
info.LoginProvider, externalClaims.ToArray());
....
}
....
}
....
}
.NET MAUI
V3105 The '_visualElement' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. AdaptiveTrigger.cs 69
void AttachEvents()
{
....
_visualElement = VisualState?.VisualStateGroup?.VisualElement;
if (_visualElement is not null)
_visualElement.PropertyChanged += OnVisualElementPropertyChanged;
_window = _visualElement.Window;
....
}
Microsoft PowerToys
V3105 The result of null-conditional operator is dereferenced inside the 'AddRange' method. NullReferenceException is possible. Inspect the first argument 'view?.OpenPictureFiles()'. MainViewModel.cs 47
public void Load(IMainView view)
{
if (_batch.Files.Count == 0)
{
_batch.Files.AddRange(view?.OpenPictureFiles()); // <=
}
....
}
public static void AddRange<T>(this ICollection<T> collection,
IEnumerable<T> items)
{
foreach (var item in items) // <=
{
collection.Add(item);
}
}
nopCommerce
V3105 The 'taxRates' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. AvalaraTaxProvider.cs 113
public async Task<....> GetTaxTotalAsync(TaxTotalRequest taxTotalRequest)
{
....
var taxRates = transaction.summary
?.Where(....)
.Select(....)
.ToList();
foreach (var taxRate in taxRates) // <=
{
if (taxTotalResult.TaxRates.ContainsKey(taxRate.Rate))
taxTotalResult.TaxRates[taxRate.Rate] += taxRate.Value;
else
taxTotalResult.TaxRates.Add(taxRate.Rate, taxRate.Value);
}
....
}
Garnet
V3105 The result of null-conditional operator is dereferenced inside the 'InitClients' method. NullReferenceException is possible. Inspect the first argument 'clusterConfig?.Nodes.ToArray()'. ShardedRespOnlineBench.cs 414
public void Run()
{
PrintClusterConfig();
Console.WriteLine($"Running benchmark using {opts.Client} client type");
InitClients(clusterConfig?.Nodes.ToArray()); // <=
Thread[] workers = InitializeThreadWorkers();
}
....
private void InitClients(ClusterNode[] nodes)
{
switch (opts.Client)
{
case ClientType.GarnetClient:
gclient = new GarnetClient[nodes.Length]; // <=
....
....
}
}
Garnet
V3105 The 'opPercent' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. EmbeddedPerformanceTest.cs 58
public EmbeddedPerformanceTest(...., Options opts, ....)
{
this.server = server;
this.opts = opts;
logger = loggerFactory.CreateLogger("EmbeddedBench");
opPercent = opts.OpPercent?.ToArray(); // <=
opWorkload = opts.OpWorkload?.ToArray(); // <=
if (opPercent.Length != opWorkload.Length) // <=
throw new Exception($"....");
....
}
Similar errors can be found in some other places:
- V3105 The 'opWorkload' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. EmbeddedPerformanceTest.cs 58
WolvenKit
V3105 The 'whenDoesTheLimitReset' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. LibraryService.cs 332
public async Task<bool> InstallAsync(....)
{
....
try
{
....
}
catch (Octokit.ApiException)
{
var apiInfo = ghClient.GetLastApiInfo();
var rateLimit = apiInfo?.RateLimit;
var howManyRequestsCanIMakePerHour = rateLimit?.Limit;
var howManyRequestsDoIHaveLeft = rateLimit?.Remaining;
var whenDoesTheLimitReset = rateLimit?.Reset;
_logger.LogInformation(
$"[Update] {howManyRequestsDoIHaveLeft}/{howManyRequestsCanIMakePerHour}" +
$" - reset: {whenDoesTheLimitReset
?? whenDoesTheLimitReset.Value.ToLocalTime()}");
return false;
}
}
ScreenToGif
V3105 The 'properties' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. UserSettings.cs 125
var properties = doc.Root?.Elements().Select(GetProperty).ToList();
....
var version = properties?.FirstOrDefault(f => f.Key == "Version") // <=
?.Value ?? "0.0";
Migration.Migrate(properties, version);
var resource = new ResourceDictionary {{"Version", All.VersionText}};
foreach (var property in properties) // <=
{
var value = ParseProperty(property);
if (value != null && !resource.Contains(property.Key))
resource.Add(property.Key, value);
}
ScreenToGif
V3105 The 'list' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible. Editor.xaml.cs 4121
if (File.Exists(Path.Combine(pathTemp, "Project.json")))
{
....
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
var ser = new DataContractJsonSerializer(typeof(ProjectInfo));
var project = ser.ReadObject(ms) as ProjectInfo;
list = project?.Frames; // <=
}
}
....
//Shows the ProgressBar
ShowProgress(LocalizationHelper.Get("S.Editor.ImportingFrames"),
list.Count); // <=