How to suppress a compiler warning to add β€œwait” in razor mode?

I am using MVC 5 and I have helper extension methods for creating links and other Expression<Action<TController>> based URLs that trigger controller actions. These expressions are obviously not called when creating the view. They are used only for metadata.

Given this excerpt from my kind of razor,

 @this.Form((AccountController c) => c.Register(null)) 

the compiler generates a warning:

Warning 1 Since this call is not expected, execution of the current method continues until the call ends. Consider applying "wait" as a result of a call.

This warning does not seem appropriate, because it can only be applied if this lambda was called, which, as I know, never happens.

Is there any way to suppress this? If not, I will probably make the action non-asynchronous.

+7
c # asynchronous asp.net-mvc razor
source share
2 answers

You can use #pragma in code blocks, as the code is then merged with the source file of the subscriber, which is compiled, and when you receive a warning.

 @{ #pragma warning disable } 

and

 @{ #pragma warning restore } 

UDATE:

You can even turn off specific alerts. See #pragma warning (C # link)

+5
source share

From MSDN:

To suppress specific warnings for Visual C # or F #

  • In Solution Explorer, select the project in which you want to suppress warnings.
  • In the menu bar, select "View", "Property Pages".
  • Select an assembly page.
  • In the Suppress warnings box, specify the error codes for the alerts you want to suppress, separated semicolons, and then rebuild the solution.

Good luck; -)

0
source share

All Articles