简体   繁体   中英

How do I resolve a NullReferenceException in CSharpUpgradeProjectCodeFixProvider in a Visual Studio extension?

The Issue

Hi, I am attempting to update an ASP.NET Framework project from C# version 5 to a more modern version of the language. However, the automatic updater errors out every time I attempt to run it and I can't find anything online on how to do it manually, nor can I find anything related to this specific issue.

Edit:
The code causing this issue is part of Visual Studio, and as such is not part of my own code, thus I don't feel it is relevant in any way to post my code. I know full well what a NullReferenceException is, I don't know how to fix a visual studio extension. For goodness sake SO, please read beyond the title. The referenced question is about fixing errors in your own code, I need to update a C# version.

Please find below the stack trace that it provides:

System.NullReferenceException : Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.LanguageServices.Utilities.ProjectPropertyStorage.PerConfigurationPropertyStorage.SetProperty(String buildPropertyName,String configurationPropertyName,String value)
   at Microsoft.CodeAnalysis.Workspace.ApplyProjectChanges(ProjectChanges projectChanges)
   at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution,IProgressTracker progressTracker)
   at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.TryApplyChanges(Solution newSolution,IProgressTracker progressTracker)
   at Microsoft.CodeAnalysis.CodeActions.ApplyChangesOperation.ApplyOrMergeChanges(Workspace workspace,Solution originalSolution,Solution changedSolution,IProgressTracker progressTracker,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeActions.ApplyChangesOperation.TryApplyAsync(Workspace workspace,Solution originalSolution,IProgressTracker progressTracker,CancellationToken cancellationToken)
   at async Microsoft.CodeAnalysis.CodeActions.CodeActionEditHandlerService.ProcessOperationsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeActions.CodeActionEditHandlerService.ApplyAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.InvokeWorkerAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformActionAsync(<Unknown Parameters>)

What I tried

So far I have explored various levels of SEO-fu to get anything even remotely related, but to no avail. When I open the Property Pages window for the project I can only go up to Target Framework 4.8 as that is the newest version. According to the Microsoft Learn site, .NET Framework should default to C# 7.3, yet the version my ASP site is using is C# 5. I know this as the tooltip when I attempt to use target-typed object creation alerts me that I am using C# 5.

Any help on this matter would be appreciated.

The "System.NullReferenceException: Object reference not set to an instance of the object" problem may be caused by the following:

  1. The ViewState object is Null.
  2. DateSet is empty.
  3. The DataReader is empty because of the sql statement or the Datebase.
  4. When declaring a string variable, apply the variable without assigning a null value.
  5. The object is not initialized with new.
  6. The Session object or application is empty.
  7. When assigning a text value to the control, the value does not exist.
  8. When using Request.QueryString(), the obtained object does not exist, or the initial value is not assigned when the value is empty.
  9. When using FindControl, the control does not exist but has not been preprocessed.
  10. Repeated definitions cause an error that the object reference is not set to the instance of the object.

If you can eliminate the above problems, then please open Visual Studio Installer to repair Visual Studio.

Thanks to @Ralf in the comments this has been resolved. I would prefer to give them the karma but I can't mark a comment as an answer.

For reference: The workaround provided was found at this link .

The workaround was to manually adjust the language version in web.config. My version of the file appeared to be missing the block of code entirely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM