0

I have some code that was taken out of mothballs and handed to me. It was built in Visual Studio 2015, and that's what I'm using to build it. The original developer can't be reached, but I'm told it always built before. I have two tests that just won't build. The offending lines look like this:

PathUtilities.DragDropWidgetToView(mainWindow, screen, true, out bool unused, out bool unused2);

Those last two parameters are the funky ones. unused and unused2 aren't defined anywhere else. While that's valid syntax for the current versions of .NET, the IDE is complaining about them.

These are the errors it throws:

CS1525 Invalid expression 'bool'
CS1003 Syntax error, ',' expected
CS1525 Invalid expression 'bool'
CS1003 Syntax error, ',' expected
CS0103 The name 'unused' does not exist in the current context
CS0103 The name 'unused2' does not exist in the current context

The usings are:

using System.Collections.Generic;
using System.Threading;
using System.Windows.Automation;
using UIAutomation.ScreenUtilities;
using UIAutomation.ScreenUtilities.Screens;

And none of them are broken. All the references are intact as well.

I've commented out the tests to get it to build, but that really isn't permitted for production code.

Clearly I need to upgrade the version of .NET that Visual Studio is using. The original developer's instructions say that VS2017 can be used, but only if the C# 7 features are disabled. I'd prefer to not have to upgrade to VS2017 since our PCs are locked-down and we aren't permitted to install anything ourselves.

Frecklefoot
  • 1,660
  • 2
  • 21
  • 52
  • 12
    "just won't build" doesn't tell us anything about the error you're seeing. That's perfectly valid C# as of C# 7 (inline declaration of out parameters) - and isn't related to test frameworks at all. – Jon Skeet Sep 04 '20 at 14:33
  • Please read [ask] and provide the actual compiler errors, as well as your research. There's nothing wrong with `out bool variableName`, unless you use a really old compiler. – CodeCaster Sep 04 '20 at 14:33
  • 10
    But VS2015 doesn't support C# 7, so I suspect that either it never *has* built on VS2015, or the developer had installed a preview of C# 7. I would suggest upgrading to a rather more modern version of Visual Studio. – Jon Skeet Sep 04 '20 at 14:34
  • 4
    As an aside, the new hotness is to give variables you don't need the name `_`. It's also serves as a signal to the compiler for optimization purposes. – itsme86 Sep 04 '20 at 14:34
  • 1
    @juharr: If they were declared elsewhere, it really wouldn't compile. But as it is, that's fine as of C# 7. – Jon Skeet Sep 04 '20 at 14:35
  • @JonSkeet Yeah, I just missed that they are being defined inline. I guess I'm just so use to seeing that done with `var`. – juharr Sep 04 '20 at 14:37
  • 2
    As a quick fix if you want it to build in VS 2015, you just need to declare the variables before that method call and take the variable type out of the arguments: `bool unused; bool unused2; PathUtilities.DragDropWidgetToView(mainWindow, screen, true, out unused, out unused2);` – itsme86 Sep 04 '20 at 14:37
  • 5
    @Jon since compilers ship as packages, the project [could have C# 7 or newer installed](https://stackoverflow.com/questions/39461407/how-to-use-c-sharp-7-with-visual-studio-2015). I've done the same while transitioning to VS 2017 on development machines and build servers which couldn't be upgraded simultaneously. That would mean it'd show up as a compiler error in the Error List as Visual Studio doesn't understand the syntax, but it would build and run just fine. – CodeCaster Sep 04 '20 at 14:37
  • 7
    @CodeCaster: Ah, that's an interesting possibility too. I guess we'll need to wait to see if the OP posts more information – Jon Skeet Sep 04 '20 at 14:39

0 Answers0