Compiler Error CS0578
The Conditional attribute is not valid on 'function' because its return type is not void
ConditionalAttribute cannot be applied to a method that has a return type other than void
. The reason for this is that any other return type for a method may be needed by another part of your program.
Example
The following sample generates CS0578. To resolve this error, you must either delete ConditionalAttribute, or you must change the return value of the method to void
.
// CS0578.cs
// compile with: /target:library
public class MyClass
{
[System.Diagnostics.ConditionalAttribute("a")] // CS0578
public int TestMethod()
{
return 0;
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for