https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.debug.assert?view=netframework-4.8
Based on this documentation the code below should generate a message box, but all it does is print to the output tab:
How can I get it to produce the message box as advertised in the Microsoft docs?
//*********************************************************
//****Assignment 6 Section 1
//*********************************************************
Console.WriteLine("\n Assignment 6 - Asserts and Try/Catch.");
string fooString = null;
int fooInt = 0;
Debug.Assert(!String.IsNullOrEmpty(fooString), "Parameter must not be empty or null.");
Debug.Assert(fooInt > 0, "Parameter must be greater than zero.");
Here is the code from Form1.cs (tried with and without the Trace.Listeners code)
namespace Unit_6_WinForm
{
public partial class Form1 : Form
{
public Form1()
{
Trace.Listeners.Clear();
DefaultTraceListener defaultTraceListener = new DefaultTraceListener();
defaultTraceListener.AssertUiEnabled = true;
Trace.Listeners.Add(defaultTraceListener);
//*********************************************************
//****Assignment 6 Section 1
//*********************************************************
Console.WriteLine("Assignment 6 - Asserts and Try/Catch. \n");
string fooString = null;
int fooInt = 0;
Debug.Assert(!String.IsNullOrEmpty(fooString), "Parameter must not be empty or null.");
Debug.Assert(fooInt > 0, "Parameter must be greater than zero.");
//*********************************************************
//****Assignment 6 Section 2
//*********************************************************
string[] fooStringArray = new string[5];
try
{
for (int index = 0; index <= fooStringArray.Length; index++)
{
var foo = fooStringArray[index];
}
}
catch (Exception ex)
{
Console.WriteLine("Array out of bounds error occurred.");
Console.WriteLine("{0} \n", ex.Message);
}
//*********************************************************
//****Assignment 6 Section 3
//*********************************************************
try
{
using (FileStream fs = File.Open("NoFileNamedThis.txt", FileMode.Open))
{
}
}
catch (Exception ex)
{
Console.WriteLine("File not found error.");
Console.WriteLine("{0} \n", ex.Message);
}
//*********************************************************
//****Assignment 6 Section 4
//*********************************************************
try
{
DivideByZero(1, 0);
}
catch (Exception ex)
{
Console.WriteLine("DivideByZero error occurred.");
Console.WriteLine("{0}", ex.Message);
}
void DivideByZero(int dividend, int divisor)
{
if (divisor == 0)
{
throw new ArgumentException("Divide by Zero");
}
}
}
}
}