Exam Prep Questions

Team-Fly    

Developing XML Web Services and Server Components with Visual C#™ .NET and the .NET Framework, Exam Cram™ 2 (Exam 70-320)
By Amit Kalani, Priti Kalani

Table of Contents
Chapter 10.  Testing and Debugging


Question 1

You are creating a .NET remoting object. You want to add code to the object to log error messages and warning messages. You want to log messages to both a log file and the Windows Application log, but you do not want a message to be duplicated. Which of the following code segments should you use?

  • A.

     FileStream fileLog = new     File.Create("RemObject.log"); EventLog eventLog = new EventLog("RemObject"); Trace.WriteLine(fileLog, "Sample Message"); Trace.WriteLine(eventLog, "Sample Message"); 
  • B.

     Trace.Listeners.Add(new     EventLogTraceListener("RemObject")); Trace.Listeners.Add(new   TextWriterTraceListeners("RemObject.log")); Debug.WriteLine("Sample Message"); Trace.WriteLine("Sample Message"); 
  • C.

     Trace.Listeners.Add(new     EventLogTraceListener("RemObject")); Trace.Listeners.Add(     new TextWriterTraceListeners("RemObject.log")); Trace.WriteLine("Sample Message"); 
  • D.

     EventLogTraceListener eventLog =    new EventLogTraceListener("RemObject"); TextWriterTraceListeners fileLog = new TextFileTraceListener("RemObject.log"); eventLog.WriteLine("Sample Message"); fileLog.WriteLine("Sample Message"); 
A1:

Answer C is correct. To log messages to custom target locations, you need to add custom listeners to the Trace.Listeners collection. This eliminates choices A and D. Answer B is incorrect because both the Debug and Trace classes share the Listeners collection, and you want to log a message only once.

Question 2

You are asked to implement tracing in an ASP.NET Web service application so that the application should display both warning and error messages when the application is run using the Debug configuration, and should display only an error message when it is run using the Release configuration of Visual C# .NET. Which of the following code segments best solves this requirement?

  • A.

     TraceSwitch traceSwitch = new TraceSwitch(    "MySwitch", "Error and Warning Switch"); #if DEBUG    traceSwitch.Level = TraceLevel.Warning; #else    traceSwitch.Level = TraceLevel.Error; #endif Trace.WriteLineIf(traceSwitch.TraceWarning, "Warning Message"); Trace.WriteLineIf(traceSwitch.TraceError, "Error Message"); 
  • B.

     TraceSwitch traceSwitch = new TraceSwitch(    "MySwitch", "Error and Warning Switch"); #if DEBUG    traceSwitch.Level = TraceLevel.Warning; #else    traceSwitch.Level = TraceLevel.Error; #endif Debug.WriteLineIf(traceSwitch.TraceWarning, "Warning Message"); Debug.WriteLineIf(traceSwitch.TraceError, "Error Message"); 
  • C.

     TraceSwitch traceSwitch = new TraceSwitch(    "MySwitch", "Error and Warning Switch"); #if TRACE    traceSwitch.Level = TraceLevel.Warning; #else    traceSwitch.Level = TraceLevel.Error; #endif Trace.WriteLineIf(traceSwitch.TraceWarning, "Warning Message"); Trace.WriteLineIf(traceSwitch.TraceError, "Error Message"); 
  • D.

     TraceSwitch traceSwitch = new TraceSwitch(    "MySwitch", "Error and Warning Switch"); #if TRACE    traceSwitch.Level = TraceLevel.Error; #else     traceSwitch.Level = TraceLevel.Warning; #endif Trace.WriteLineIf(traceSwitch.TraceWarning, "Warning Message"); Trace.WriteLineIf(traceSwitch.TraceError, "Error Message"); 
A2:

Answer A is correct. Because the DEBUG symbol is defined in the Debug configuration, the Level property of traceSwitch is set to TraceLevel.Warning. This causes both the TraceWarning and TraceError properties of the TraceSwitch object to evaluate to true, resulting in both of the messages being displayed. In the Release configuration, where only the TRACE symbol is defined, the Level property of traceSwitch is set to TraceLevel.Error. This causes the TraceWarning property to return a false value and the TraceError property to return a true value, so only the error messages are displayed. Answer B is incorrect because the Debug class is used to generate the output, so no messages are displayed in the Release configuration. Answer C is incorrect because it displays warning and error messages in the Release configuration and displays only warning messages in the Debug configuration. Answer D is incorrect because the TRACE symbol is defined in both the Debug and Release configurations, resulting in the display of only error messages for both the Debug and Release configurations.

Question 3

Your application has a bunch of serviced components that execute the business logic. All the serviced components are marked with the Transaction (TransactionOption.Required) attribute. All the methods in the components are marked with the AutoComplete attribute. While testing the application, you find that inventory is not being updated properly. When you attempt to debug the application, a System.Runtime.InteropServices.COMException is thrown. The exception includes the following message: "The root transaction wanted to commit, but transaction aborted." You also find that this exception occurs only during the debugging session, not when the components run outside of the debugger. You need to resolve this problem so that you can debug the application to find the problem with inventory updates. Which of the following options should you select to resolve this problem?

  • A. Remove the AutoComplete attribute from each method. Within each method implementation, add calls to the ContextUtil.SetComplete() and ContextUtil.SetAbort() methods.

  • B. Remove the AutoComplete attribute from each method. Within each method implementation, add calls to the ContextUtil.MyTransactionVote and ContextUtil.DeactivateOnReturn properties.

  • C. Use the Component Services administrative tool. Access the Properties dialog box for My Computer and increase the transaction timeout duration.

  • D. Change the implementation of each method in the serviced component with the following code segment:

     try {     // the business logic goes here } catch {    //log any error messages here } finally {    ContextUtil.SetComplete(); } 
A3:

Answer C is correct. When you debug a program, the transaction might not complete in the set timeframe (the default is 60 seconds). In that case, the program throws the given exception. Because you have a bunch of components here, instead of setting the transaction timeout value for each of them individually, you can set the transaction timeout property for the applications running on the computer. Answers A, B, and D are incorrect because the ContextUtil class does not provide any property or method to directly impact the transaction timeout.

Question 4

You are debugging a Web form that involves long calculation and iterations. You want to break into the code to watch the values of variables whenever the value of intValue changes in the following statement:

 intValue = ProcessValue(intValue); 

Which of the following options will quickly allow you to achieve this?

  • A. Run the application using step execution mode. Then use the Step Out key to step out of the execution from the ProcessValue() method. Use the Immediate window to display the value of intValue before and after this line of code executes.

  • B. Set a breakpoint at the given statement and set the Hit Count option to Break When Hitcount Is Equal to 1.

  • C. Set the breakpoint at the given statement. In the Breakpoint Condition dialog box, enter intValue != intValue and check the Is True option.

  • D. Set the breakpoint at the given statement. In the Breakpoint Condition dialog box, enter intValue and check the Has Changed option.

A4:

Answer D is correct. When you want to break into the code when the value of a variable changes, the quickest approach is to set a conditional breakpoint and check the Has Changed option. Answer A is incorrect because this solution requires you to constantly monitor the values of the variables. Answer B is incorrect because the hit count counts only the number of times a statement has been executed. Answer C is incorrect because an inequality comparison of a variable with itself always results in a false value, so the breakpoint will never be hit.

Question 5

Which of the following statements are true for remote debugging of processes? (Select all that apply.)

  • A. Both the local and the remote machines should have Visual Studio .NET installed.

  • B. Only the local machine needs Visual Studio .NET.

  • C. Remote Components Setup is required on the local machine.

  • D. Remote Components Setup is required on the remote machine.

A5:

Answers B and D are correct. You need to have Visual Studio .NET on the local machine to debug the remote processes. In addition, you need to run Remote Components Setup on the remote machine. Answer A is incorrect because, for remote debugging, Visual Studio .NET is not required on the remote machine. Answer C is incorrect because, for remote debugging, Remote Components Setup is not required on the local machine.

Question 6

You create a serviced component named ConnectionDispenser. This component is stored in the DbUtils.dll assembly and is registered in the COM+ catalog. The serviced component is configured to be activated as a library application. You discover that the CreateNewConnection() method is not working as expected. You want to debug any calls to this method. What should you do?

  • A. Open the ConnectionDispenser solution. Set a breakpoint on the CreateNewConnection() method. Start the debugger.

  • B. Open the solution for the client program. Set a breakpoint on the statement that calls the ConnectionDispenser.CreateNewConnection() method. Start debugging the client program.

  • C. Attach the debugger to the DbUtils.dll process. Set a breakpoint on the CreateNewConnection() method.

  • D. Attach the debugger to a dllhost.exe process. Set a breakpoint on the CreateNewConnection() method.

A6:

Answer B is correct. A serviced component activated as a library application runs in the process of its caller. Therefore, to debug such an application, you can set a breakpoint in the client application and then step into the serviced component code. Answers A and C are incorrect because the serviced component activated as a library application runs in the process of its caller, thus requiring you to debug the client program. Answer D is incorrect because dllhost.exe hosts the component only when the component is a server-activated component.

Question 7

You are debugging a .NET remoting object that heavily uses SQL Server stored procedures. One of the methods of the .NET remoting object calls the YTDSales stored procedure. The stored procedure uses a variable named @Sales. You want to see how the value of this variable changes as the code in the stored procedure executes. Which of the following options will allow you to easily do this?

  • A. Use the SQL Server PRINT command to display the value of the @Sales variable at different places.

  • B. Use the Debug.Write statement to print the value of the @Sales variable.

  • C. Use the Trace.Write statement to print the value of the @Sales variable.

  • D. Use the Locals window to monitor the value of @Sales as you step through the stored procedure.

A7:

Answer D is correct. You can use the Locals window to keep track of the values of the variables defined in the stored procedure during its step-by-step execution. Answer A is incorrect because the SQL Server PRINT command is not available within Visual Studio .NET. Answers B and C are incorrect because in these cases, you need to write additional code to monitor the value of the @Sales variable.

Question 8

While debugging your ASP.NET Web form, you want to display the trace messages as part of the page execution details. Which of the following methods should you use? (Select two.)

  • A. TraceContext.Write()

  • B. TraceContext.Warn()

  • C. System.Diagnostics.Trace.Write()

  • D. System.Diagnostics.Debug.Write()

A8:

Answers A and B are correct. The trace messages written using the TraceContext.Write() and TraceContext.Warn() methods can append trace messages to other tracing information in the page output. Answers C and D are incorrect because the trace messages written using the Trace.Write() and Debug.Write() methods of the System.Diagnostics namespace are written to the Output window of Visual Studio .NET by default.

Question 9

You have added the following statement to the Load event handler of a single-page Web application:

 Trace.Listeners.Add(new TextWriterTraceListener ("TraceLog.txt")) 

Which of the following statements are true with respect to program execution? (Select all that apply.)

  • A. TextWriterTraceListener will listen to all messages generated by the methods of the Debug and Trace classes.

  • B. TextWriterTraceListener will listen to only the messages generated by the methods of the Trace classes.

  • C. All the trace messages will be stored in a file named TraceLog.txt.

  • D. The trace messages are displayed in the Output window while running the program in either the Debug or Release configurations.

A9:

Answers A, C, and D are correct. When the new listener is added to the Trace class, it is also added to the Listeners collection. The Listeners collection already has a DefaultTraceListener object that sends messages to the Output window. Therefore, you have messages in TraceLog.txt as well as in the Output window. Answer B is incorrect because, when you add a listener to the Trace.Listeners collection, it listens to the messages generated by both the Trace and Debug classes.

Question 10

While you are debugging in Visual Studio .NET, you want to watch only the values of those variables you are using in the current statement and its previous statement. Which of the following debugger windows is the easiest way to watch these variables?

  • A. Autos

  • B. Locals

  • C. This

  • D. Watch

A10:

Answer A is correct. The Autos window gives you the most convenient access because it automatically displays the names and values of all the variables in the current statement and the previous statement at every step. Answer B is incorrect because the Locals window displays the value of all the local variables in the current scope. Answer C is incorrect because the This window displays only the data members of the object associated with the current method. Answer D is incorrect because the Watch window displays only the value of the selected variables and expressions.


    Team-Fly    
    Top


    MCAD Developing XML Web Services and Server Components with Visual C#. NET and the. NET Framework Exam Cram 2 (Exam Cram 70-320)
    Managing Globally with Information Technology
    ISBN: 789728974
    EAN: 2147483647
    Year: 2002
    Pages: 179

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net