Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress compiler warning to add "await" inside razor view?

I'm using MVC 5, and I have helper extension methods to generate links and other urls based on Expression<Action<TController>>s that invoke controller actions. These expressions obviously aren't invoked in generating the view. They are only used for metadata.

Given this excerpt from my razor view,

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

the compiler generates a warning:

Warning 1 Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

This warning doesn't seem appropriate because it could only apply if that lambda were invoked, which I know never happens.

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

like image 466
recursive Avatar asked Sep 15 '14 22:09

recursive


People also ask

How to disable warning in Visual Studio code?

If you want to hide a particular warning code across your entire project, open the overall properties through the Project | Properties menu command, and when the properties appear, select the Build page. The Suppress Warnings box on that page accepts a semicolon-delimited list of codes.

How do you suppress warnings in C++?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.

Which number is used to suppress the warning in a code?

Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.


1 Answers

You can use #pragma in code blocks, as the code is then merged to a single source file, which is compiled, and when you get the warning from.

@{ #pragma warning disable }

and

@{ #pragma warning restore }

UDATE:

You can even disable specific warnings. See #pragma warning (C# Reference)

like image 133
George Polevoy Avatar answered Sep 30 '22 03:09

George Polevoy