0

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.

  • I don't think I made it clear, but the error is not in my code. It is part of Visual Studio that is having this issue. – TimesNewRobot Dec 16 '22 at 14:19
  • Framework versions and C# version are 2 different things so using Net Framework 4.8 for example would mean using also c# 7.3. Documentation [here](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version) shows their connection. Actually you should just change the target in your project files don't know what the Extension does or tries todo beyond that. Presumably updating references assemblies you need to update but you wan't to change language version NOT framework version right? – Ralf Dec 16 '22 at 14:32
  • @Ralf The extension is part of VS by default and is supposed to resolve errors like CS8025, the issue itself is that it's supposed to be 7.3, but it's using c# 5. – TimesNewRobot Dec 16 '22 at 14:34
  • @Ralf Yes, the language version is what I want to update, the trouble is that it's an ASP site, so it doesn't have a csproj file – TimesNewRobot Dec 16 '22 at 14:36
  • The used language version should be set in you web.config then. This one may help https://stackoverflow.com/questions/56130824/how-to-use-c-sharp-6-0-or-7-0-in-an-old-asp-net-website-not-website-project – Ralf Dec 16 '22 at 14:57
  • @Ralf That worked, can you submit it as an answer so I can mark it as completed? – TimesNewRobot Dec 16 '22 at 15:15

2 Answers2

0

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.

wenbingeng-MSFT
  • 1,546
  • 1
  • 1
  • 8
  • Thanks for answering, but it has already been resolved by Ralf in the comments. The error is not in my code. It is part of Visual Studio that is having this issue. I've fixed the problem I was having by using the alternate route Ralf suggested. – TimesNewRobot Dec 21 '22 at 17:34
  • That's great. You can mark his comment as answer. – wenbingeng-MSFT Dec 22 '22 at 05:51
0

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>