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.
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.
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.
Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With