2

I have been developing a website with ASP.Net and using "dotnet watch" to view progress as I go. Everything had been working fine, but today I updated VS and now whenever I make a change and save to view the change on the website, it gives me a "HTTP ERROR 500". I attached a screenshot from my powershell and have no idea what's going on. I am going to revert to the previous version for now so I can keep working, but if anyone has a soulution or knows whats going on please let me know.

Edit: I seem to have narrowed it down to editing Layout.cshtml while using dotnet watch to be causing the error. My other pages are fine but am concerned for when the website is deployed.

Error message from Visual Studio PowerShell:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HMK58AJSOF5Q", Request id "0HMK58AJSOF5Q:00000007": An unhandled exception was thrown by the application.
      System.AggregateException: An error occurred while writing to logger(s). (Could not load type 'PortaBlu.Pages.Pages_Index+<ExecuteAsync>d__34#1' from assembly 'PortaBlu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.) (Could not load type 'PortaBlu.Pages.Pages_Index+<ExecuteAsync>d__34#1' from assembly 'PortaBlu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.)
       ---> System.TypeLoadException: Could not load type 'PortaBlu.Pages.Pages_Index+<ExecuteAsync>d__34#1' from assembly 'PortaBlu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
         at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, RuntimeType type, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
         at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
         at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
         at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
         at System.Reflection.RuntimeMethodInfo.GetCustomAttributes(Type attributeType, Boolean inherit)
         at System.Attribute.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit)
         at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element, Boolean inherit)
         at System.Diagnostics.StackTrace.TryResolveStateMachineMethod(MethodBase& method, Type& declaringType)
         at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat, StringBuilder sb)
         at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
         at System.Exception.get_StackTrace()
         at System.Exception.ToString()
         at Microsoft.Extensions.Logging.Console.SimpleConsoleFormatter.CreateDefaultLogMessage[TState](TextWriter textWriter, LogEntry`1& logEntry, String message, IExternalScopeProvider scopeProvider)
         at Microsoft.Extensions.Logging.Console.SimpleConsoleFormatter.Write[TState](LogEntry`1& logEntry, IExternalScopeProvider scopeProvider, TextWriter textWriter)
         at Microsoft.Extensions.Logging.Console.ConsoleLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
         at Microsoft.Extensions.Logging.Logger.<Log>g__LoggerLog|12_0[TState](LogLevel logLevel, EventId eventId, ILogger logger, Exception exception, Func`3 formatter, List`1& exceptions, TState& state)
         --- End of inner exception stack trace ---
         at Microsoft.Extensions.Logging.Logger.ThrowLoggingError(List`1 exceptions)
         at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
         at Microsoft.Extensions.Logging.Logger`1.Microsoft.Extensions.Logging.ILogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
         at Microsoft.Extensions.Logging.LoggerMessage.<>c__DisplayClass8_0.<Define>g__Log|0(ILogger logger, Exception exception)
         at Microsoft.AspNetCore.Diagnostics.DiagnosticsLoggerExtensions.UnhandledException(ILogger logger, Exception exception)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
       ---> (Inner Exception #1) System.TypeLoadException: Could not load type 'PortaBlu.Pages.Pages_Index+<ExecuteAsync>d__34#1' from assembly 'PortaBlu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
         at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, RuntimeType type, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
         at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
         at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
         at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
         at System.Reflection.RuntimeMethodInfo.GetCustomAttributes(Type attributeType, Boolean inherit)
         at System.Attribute.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit)
         at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element, Boolean inherit)
         at System.Diagnostics.StackTrace.TryResolveStateMachineMethod(MethodBase& method, Type& declaringType)
         at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat, StringBuilder sb)
         at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
         at System.Exception.get_StackTrace()
         at System.Exception.ToString()
         at System.Text.StringBuilder.Append(Object value)
         at Microsoft.Extensions.Logging.EventLog.EventLogLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
         at Microsoft.Extensions.Logging.Logger.<Log>g__LoggerLog|12_0[TState](LogLevel logLevel, EventId eventId, ILogger logger, Exception exception, Func`3 formatter, List`1& exceptions, TState& state)<---
5
  • Dont think this has anything to do with upgrading VS, I could be wrong though... Try deleting the bin and obj folders from Windows Explorer, then try recompiling your project. Commented Aug 23, 2022 at 21:35
  • @mxmissile You're right, I uninstalled VS and reinstalled the same version because I realized it wasn't the update after uninstalling lol. Commented Aug 23, 2022 at 22:09
  • @mxmissile I deleted both bin and obj folders and recompiled, but still got error. Commented Aug 25, 2022 at 18:00
  • does Pages/Index.cshtml exist in your project? Commented Aug 25, 2022 at 19:48
  • Yes, I have index. I also wanted to test something and created a new project but it gave me the same error on both index.cshtml and layout.cshtml pages Commented Aug 25, 2022 at 22:02

3 Answers 3

5

I found a workaround for the time being. The Problem exists for .NET SDK v6.0.400.

  1. Go to .NET 6.0 SDK v6.0.302 and download this version (previous version as of 9/6/2022). Type dotnet --info to see if it installed properly.

  2. Inside of your project, add a new text file and label it global.json. Inside of the file, type this:

    {
      "sdk": {
        "version": "6.0.302"
      }
    }

global.json reference

Don't include rollForward as it would use the newest version which causes the problem.

The global.json file forces your project to use the specified version instead of the newest. If you downloaded a different version than SDK v6.0.302, then change the global.json accordingly.

Use this until Microsoft releases a patch to fix this bug. Hopes this helps!

Sign up to request clarification or add additional context in comments.

2 Comments

I'm still have the issue with SDK 6.0.302 :(
@Jerome2606 SDK v6.0.302 was just an example, just download and replace the version that you were previously using that worked.
0

As a temporary solution you can start the app in debug mode from Visual Studio (CTRL+F5) and have the "Hot reload on file save" checked.

Comments

0

This appears to be a known bug, whose fix is already on the way. See one of the related Github issues.

1 Comment

Great to hear, I was concerned it was a problem with my machine because I couldn’t find anything online about it. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.