Click here to Skip to main content
14,921,581 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Visual Studio version: Visual Studio 2019 Enterprise, v16.9.2
Windows version: Windows 10 Professional 64-bit Version 1909 (OS Build: 18363.1198)

I have no control over the Windows Updates as this code is on a VM.

Hi all,

I just recently posted this on the Visual Studio Feedback forums. I am getting weird behavior from the C# return keyword. My language version is C# 7.3, with .NET Framework 4.8.

As a programmer with deep experience in C-style languages, my understanding is that the return keyword should immediately stop executing the currently-running method: no passing GO, no collecting $200.

However, in my debugging session (and running executable), the following is occurring:

C# return keyword does not work - animation on Imgur[^]

What is going on is, the debugger correctly activates a call to the return keyword and then jumps, not to the close curly brace of the containing method, but rather to the method's final statement. I am encountering this behavior in other places of my code as well.

Is there something not configured correctly, or am I simply stroking out? :-D

Thank you in advance for any suggestions and/or advice.

Sincerely Yours,



Brian Hart

What I have tried:

Looking at Project Properties, searching Google.
Posted
Updated 27-Mar-21 6:48am
Comments
Richard MacCutchan 27-Mar-21 12:40pm
   
I would suggest you rebuild the project. I have seen similar problems when the source and executable are out of sync. It would probably also help if you posted the code here so people could examine it.
Brian C Hart 27-Mar-21 12:47pm
   
@Richard - actually I have found the issue. I am using PostSharp[^] v6.9.3 in my project. When I decorate the offending method with their [Log(AttributeExclude = true)] attribute, which suppresses weaving for this method, then the issue goes away.

However, I hate to have to think that it will be necessary to disable this for all my code's methods that early-return!

1 solution

I am using PostSharp[^] v6.9.3 in my project. When I decorate the offending method with their [Log(AttributeExclude = true)] attribute, which suppresses weaving for this method, then the issue goes away.

However, I hate to have to think that it will be necessary to disable this for all my code's methods that early-return!

I have filed a bug report on their issue-tracking system[^], and hopefully, the issue will be resolved soon.
   
v4
Comments
BillWoodruff 27-Mar-21 20:14pm
   
I have found PostSharp support excellent.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900