Fresh ASP.NET Core MVC projects throwing exceptions - c#

So, I made a fresh ASP.NET Core Web App (Model-View-Controller) project in visual studio 2022 and .NET 6 like shown below.
When I start the project (without changing anything) I get the following 3 exceptions:
Exception thrown: 'System.IO.IOException' in System.Net.Security.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
However the project still runs and the website opens as expected.
Are these exceptions something to worry about?

The fact that an exception is thrown is not a problem. Exceptions get thrown. That's what they do. It's a problem when they aren't caught and managed appropriately. If your code isn't even seeing those exceptions then they are being caught and handled in system code, so they're not relevant to you. If your application crashes, that is an unhandled exception, so you need to look at why it's being thrown and whether or not you need to prevent it and/or catch it and clean up.

Related

Exceptions thrown in Output window by mscorlib.dll, System.Data.dll and EntityFramework.dll

I removed a dynamic filter from OnModelCreating and the related NuGet package, EntityFramework.DynamicFilters, from my application as it is no longer required. As soon as I did this I started seeing Exceptions being thrown in the Output Window.
First when I run my application (C# with WPF and EF) I get:
Exception thrown: 'System.TypeLoadException' in mscorlib.dll
Then when I access my Data (Entity Framework) I get a whole bunch of exceptions when my code reaches this statement:
public List<T> GetAll() => Table.ToList();
The errors include:
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
Exception thrown: 'System.Data.SqlClient.SqlException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.EntityCommandExecutionException' in EntityFramework.SqlServer.dll
The odd thing is that data is returned as expected and the application appears to be working, however, my gut tells me not to simply ignore them and hope for the best.
Taking advice from other posts I deleted the content of the Debug folder, Cleaned Solution and Rebuilt solution with no improvement.
Following other advice I uninstalled and re-installed Microsoft.Net Core and Microsoft.Net Framework, also with no improvement. My application is targeting .Net Framework 4.8
I removed and repaired the Entity Framework NuGet package, still no help.
To make 100% sure it was not a bug in my code I cloned the application to a different machine and it ran perfectly first time. (Edit: for clarity I also created a new folder on problematic machine and cloned to that with same problem) This tells me it must be something in my environment, but what?
I am all out of ideas, short of formatting by hard drive and re-installing Windows which I actually seriously considered a few time in the last 24 hours.
Reading https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019 prompted me to compare the debug settings on the two machines. Turns out that the problematic machine had Enable Just My Code unchecked. Checking it makes my problem "go away". The question now I suppose is whether it is safe to simply ignore exception which are "not in my code"?
After much research, my problem turned out to be the Debug setting in Visual studio which was not set to "Enable Just My Code". (Tools -> Options -> Debugging Tab, Enable Just My Code). https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019
From what I can gather from Google, it is safe enough to ignore minor errors originating from external assemblies. Assuming they are not impacting your program logic that is. I am not 100% comfortable with ignoring exceptions, but be that as it may.

InvalidOperationException: Could not locate the hub named 'Roslyn'

I'm making a Roslyn diagnostic. When debugging the diagnostic, which launches a separate instance of Visual Studio, I get the following exception:
Exception thrown: 'System.InvalidOperationException' in
Microsoft.VsHub.Client.dll
Additional information: Could not locate the hub named 'Roslyn'
No further details are given. What does this exception mean? What can I do about it? I'm quite confused because earlier I was able to debug this project just fine. I've tried to 'git clean -f -x -d' but to no avail.
As discussed, Visual Studio throws a lot of exceptions during startup. Debugging tips are either:
Enable "Just My Code" under Debugging > General in Tools Options.
In the Exception Settings window, make sure breaking on an exception being thrown is off.

System.AccessViolationException in C# only when debugging in X64

I create a new C# Windows Form project in Visual Studio 2013 Update 5. I do not change it in any way. It debugs properly as usual. As soon as I change the Platform target to x64, the debugger shows this error:
System.AccessViolationException was unhandled
Message: An unhandled exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
This happens in every 5 times of debugging. Do you have any idea on what may be causing this error and how it can be fixed?

An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll but was not handled in user code in MVC 5 Web Application

I'm trying to create MVC 5 application using Visual Studio 2015 that consist a forums(discussions).
Followed this video and try to configure MVCForum with MVCForum.Identity
So for that I used to integrate already built system(mvcforum) with my MVC 5 Project When I Compile it hasn't any error but when I debug this I'm getting following error in Global.asax.cs File
An exception of type 'System.Reflection.TargetInvocationException'
occurred in mscorlib.dll but was not handled in user code

A first chance exception of type 'System.IndexOutOfRangeException' occurred in mscorlib.dll

I have a WCF project (.NET 4.5) and when I call a long running function on it, I'm getting this error:
A first chance exception of type 'System.IndexOutOfRangeException' occurred in mscorlib.dll
in the output window, but the thing is when I debug the project, there are no exceptions thrown in the project and the project keeps running/debugging as if no error happened. I thought that if there was an exception in my code, it should break and show the stack trace, but in this case no errors and keeps running. I'm seeing this information like a lot. It fills the output window and keeps going/adding
Do anyone know what this error means? Why am I not getting unhandled exception thrown error if this is true?

Categories