skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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.

    <system.codedom>
        <compilers>
          <compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" 
            compilerOptions="/langversion:7.3 /nowarn:1659;1699;1701;612;618" 
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, 
                  Microsoft.CodeDom.Providers.DotNetCompilerPlatform, 
                  Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4" 
            compilerOptions="/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=&quot;Web&quot; /optionInfer+" 
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, 
                  Microsoft.CodeDom.Providers.DotNetCompilerPlatform, 
                  Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </compilers>
      </system.codedom>
    

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search