Compiling give warning C0162 and some scripting isn't working

I finished a full project with 1 form and multiple functions. When I compile the code I receive the message below. The build is compiled but I noticed some functions are not executed when I test the file. I use a DataGridView and when an row is selected a functions resolves related data. In Debug mode this works great after compiling it’s gone.

When I try to find logs I can’t find anything that is related to the Unreadable Code.

Any ideas?

VERBOSE: Checking dotnet version.
VERBOSE: 3.1.201

VERBOSE: 3.1.201

VERBOSE: Creating package project.
VERBOSE: Using .NET Framework version: net462
VERBOSE: Restore completed in 166.83 ms for C:\Users…AppData\Local\Temp\2\89845168caaf4550b5362caa73b68f28\Main.csproj.

VERBOSE: Restore completed in 166.83 ms for C:\Users…\AppData\Local\Temp\2\89845168caaf4550b5362caa73b68f28\Main.csproj.

VERBOSE: Packaging C:\Users…\AppData\Local\Temp\2\Main.ps1 -> C:…\out\Main.exe
VERBOSE: Microsoft ® Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright © Microsoft Corporation. All rights reserved.

Restore completed in 50.98 ms for C:\Users…\AppData\Local\Temp\2\89845168caaf4550b5362caa73b68f28\Main.csproj.
ConsolePowerShellHost.cs(54,17): warning CS0162: Unreachable code detected [C:\Users…\AppData\Local\Temp\2\89845168caaf4550b5362caa73b68f28\Main.csproj]
Main -> C:…\out\Main.exe

Build succeeded.

ConsolePowerShellHost.cs(54,17): warning CS0162: Unreachable code detected [C:\Users…AppData\Local\Temp\2\89845168caaf4550b5362caa73b68f28\Main.csproj]
1 Warning(s)
0 Error(s)

Time Elapsed 00:00:01.05

VERBOSE: Microsoft ® Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright © Microsoft Corporation. All rights reserved.

Restore completed in 50.98 ms for C:\Users…\AppData\Local\Temp\2\89845168caaf4550b5362caa73b68f28\Main.csproj.
ConsolePowerShellHost.cs(54,17): warning CS0162: Unreachable code detected [C:\Users…\AppData\Local\Temp\2\89845168caaf4550b5362caa73b68f28\Main.csproj]
Main -> C:…\out\Main.exe

Build succeeded.

ConsolePowerShellHost.cs(54,17): warning CS0162: Unreachable code detected [C:\Users…\AppData\Local\Temp\2\89845168caaf4550b5362caa73b68f28\Main.csproj]
1 Warning(s)
0 Error(s)

Time Elapsed 00:00:01.05

Is there anyway you can share some of your code? Sounds like it should work but it would be handy to look at the implementation.

Yes of course. Let me know how you want me to share. I can send you an OneDrive link (private). Or we can do a remote session later this afternoon or somewhere next week.

Just let me know what you prefer.

Hi Adam,

I’m getting the same warning,
I also have a form, no DataGridView Just a Couple of ComboBoxes, Buttons, TextBoxes and a RichTextBox.
The Code and the Application work all fine at the end, I just don’t get why I get the Warning.

Thx

I get the same warning when compliling a script