Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConditionalClassAttribute throws in cases where ConditionalFact/ConditionalTheory do not throw

See original GitHub issue

Last week, @Jozkee and I I worked on this PR and this PR in which we added unit tests that had to create symbolic links.

Some operating systems are unable to create symlinks: iOS, Android, tvOS and Browser. This is why I had to add a Conditional* attribute that would call the method CanCreateSymbolicLinks.

The CanCreateSymbolicLinks method tries to create a symbolic link in the current OS, and returns false if it was unable to do so.

There are two different places where we define a CanCreateSymbolicLinks method, but they both do exactly the same work: FileSystemWatcherTest and FileSystemTest (which then calls MountHelper).

Initially, we both decided to add ConditionalClass on top of our new test classes, but our CI runs failed in the aforementioned operating systems, because System.Diagnostics.Process is not supported:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) in System.Diagnostics.Process.dll:token 0x6000105+0xe
   at System.Diagnostics.Process.Start() in System.Diagnostics.Process.dll:token 0x60000de+0xab
   at System.IO.Tests.FileSystemWatcherTest.CreateSymLink(String targetPath, String linkPath, Boolean isDirectory) in System.IO.FileSystem.Watcher.Tests.dll:token 0x6000129+0x8c

I decided to fix my tests by changing ConditionalClass for ConditionalFact and ConditionalTheory (see here) and the CI passed. This tells me that ConditionalFact and ConditionalTheory are wrapped by a large try catch that returns false if an exception is thrown.

@Jozkee decided to fix the CanCreateSymbolicLinks method he’s consuming by checking the OS, and if it’s unsupported, return false. While I think this fix is fine to get him unblocked, I think this is just a workaround and not a fix to the actual problem.

Since we own ConditionalClass in this repo, can it be fixed to also try catch all exceptions and return false?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

riarenascommented, Jun 3, 2021

Added to dotnet/arcade#363 @ViktorHofer @safern FYI in case you have something to chime in in this area.

ViktorHofercommented, Jun 3, 2021

We own this library an do not expect core-eng to follow up on issues. Should we add a code owners entry for so that we at least get notified of prs targeting the code?

Regarding the issue, will take a look. cc @akoeplinger

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't I use ConditionalAttribute on a class?
Yes, ConditionalAttribute is a special case, being one of only a few attributes that are specifically handled directly by the compiler.
Read more >
ConditionalAttribute Class (System.Diagnostics)
Indicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined.
Read more >
Assigning Conditional Values in Class : r/learnpython
My question is regarding attributes in classes. In this class, the attribute will always have two values depending on the what number is...
Read more >
Angular NgClass Example – How to Add Conditional CSS ...
ngClass is a directive in Angular [] that adds and removes CSS classes on an HTML element.
Read more >
Applying React Conditional classNames
Depending on your preferences and needs, you can apply conditional classNames with a ternary or with a library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found