You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to make an API in Visual Studio, using net 5.0.7 and the APS.NET Core Web API template.
My application keeps crashing, before even hitting the first line of code in Program.cs In the output window, the only information shown was:
'xxx.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Runtime.dll'.
The program '[0x254C] xxx.exe: Program Trace' has exited with code 0 (0x0).
The program '[0x254C] xxx.exe' has exited with code 0 (0x0).
I couldn't figure out was wrong, so I started from scratch to pin point the issue. Turns out that I had a semicolon in Startup.cs after my usings like this:
using System;
using System.IO.Compression;
using System.Runtime.InteropServices;
;
When removing the semicolon on the last line, the application worked as expected.
I know I have a compiler warning, 'Remove this empty statement', and I know I should have solved it, but I didn't expect the application to crash like this. IMHO, the compiler should have raised an error, or the application should have raised a nice descriptive exception message.
Configuration
Tested in on Windows 10 and on Fedora Linux 33, in both cases with the same result.
Regression?
Do not know, tested it with net 5.0.5 as well on Windows, same result.
Other information
none
The text was updated successfully, but these errors were encountered:
The problem is that the application is not crashing, it's doing exactly what you told it to do, which is nothing. C# 9 introduced top-level statements, which means you can have statements outside of a class and those take priority over Program.Main. So your program executes the empty statement and then immediately exits.
But this specific case is clearly confusing, so it will become an error in a future version of C#, see dotnet/roslyn#53472.
Description
I was trying to make an API in Visual Studio, using net 5.0.7 and the APS.NET Core Web API template.
My application keeps crashing, before even hitting the first line of code in Program.cs In the output window, the only information shown was:
'xxx.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.7\System.Runtime.dll'.
The program '[0x254C] xxx.exe: Program Trace' has exited with code 0 (0x0).
The program '[0x254C] xxx.exe' has exited with code 0 (0x0).
I couldn't figure out was wrong, so I started from scratch to pin point the issue. Turns out that I had a semicolon in Startup.cs after my usings like this:
using System;
using System.IO.Compression;
using System.Runtime.InteropServices;
;
When removing the semicolon on the last line, the application worked as expected.
I know I have a compiler warning, 'Remove this empty statement', and I know I should have solved it, but I didn't expect the application to crash like this. IMHO, the compiler should have raised an error, or the application should have raised a nice descriptive exception message.
Configuration
Tested in on Windows 10 and on Fedora Linux 33, in both cases with the same result.
Regression?
Do not know, tested it with net 5.0.5 as well on Windows, same result.
Other information
none
The text was updated successfully, but these errors were encountered: