2

In Visual Studio 2017 we have a C#, ASP.NET, MVC project that fails to build when we inline the out variable declaration for int.TryParse, as suggested by Intellisense. The project successfully builds when we declare the variable before executing int.TryParse. We have Visual Studio 2017 version 4.7.02053. The Target Framework is 4.5.2.

This pattern builds in VS 2017.

int consumerID = 0;
int.TryParse(model.TextConsumerID, out consumerID);

This pattern fails to build in VS 2017.

int.TryParse(model.TextConsumerID, out int consumerID);

We use the first pattern in multiple places in the application. When we inline any of the int.TryParse declarations, per the Intellisense suggestion, then Visual Studio fails to build and shows 0 Errors and 0 Warnings. If I have any classes opened that contain other int.TryParse commands that are not inlined, then the following Messages will appear: "Variable declaration can be inlined."

Both patterns should work.

The "Treat warnings as errors" option is set to "None" under the project Properties > Build tab. There is no visible option for treating Messages as errors.

Is this a Visual Studio 2017 bug, or is there some build setting that I need to adjust to fix this? Thanks.

16
  • 5
    The version of visual studio is not as important as the .NET Framework version your project is targeting. Your second example was not valid until C# 7 Commented Aug 27, 2018 at 16:11
  • 1
    What's the target framework version for the project? Commented Aug 27, 2018 at 16:11
  • Thanks, I added that to the question. Commented Aug 27, 2018 at 16:13
  • 1
    Not an exact dup, but the same question about a different C# 7 feature: stackoverflow.com/questions/42482520/… Commented Aug 27, 2018 at 16:15
  • 1
    Ah, so this is not a Visual Studio problem, this is a ASP.NET MVC dynamic compilation problem. Let me find the solution to that. Commented Aug 27, 2018 at 16:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.