Convert a piece of C# to VB.NET code RRS feed

  • Question

  • namespace WebAPITest  
        using System.Net;  
        public class CustomExceptionFilter: ExceptionFilterAttribute  
            public override void OnException(HttpActionExecutedContextactionExecutedContext)  
                string exceptionMessage = string.Empty;  
                if (actionExecutedContext.Exception.InnerException == null)  
                    exceptionMessage = actionExecutedContext.Exception.Message;  
                    exceptionMessage = actionExecutedContext.Exception.InnerException.Message;  
                //We can log this exception message to the file or database.  
                var response = newHttpResponseMessage(HttpStatusCode.InternalServerError)  
                    Content = newStringContent(“An unhandled exception was thrown by service.”),  
                    ReasonPhrase = "Internal Server Error.Please Contact your Administrator."  
                actionExecutedContext.Response = response;  

    This line I am having trouble converting to VB, and I have tried a couple of ways with no success.

     var response = newHttpResponseMessage(HttpStatusCode.InternalServerError) 

    Imports System.Net
    Imports System.Web.Http.Filters
    Public Class CustomExceptionFilter
        Inherits ExceptionFilterAttribute
        Public Overrides Sub OnException(actionExecutedContext As HttpActionExecutedContext)
            Dim exceptionMessage as String = String.Empty
            If IsNothing(actionExecutedContext.Exception.InnerException ) Then
                exceptionMessage = actionExecutedContext.Exception.Message
                exceptionMessage = actionExecutedContext.Exception.InnerException.Message
            End If
            dim response =  (HttpStatusCode.InternalServerError)newHttpResponseMessage
        End Sub
    End Class

    Wednesday, August 8, 2018 7:30 PM


  • Oh silly me, the site that has the code has like messed up the code example. When I pasted it into a C# class to look at it, I saw the correction needed.

    dim response =  new HttpResponseMessage(HttpStatusCode.InternalServerError)

    • Marked as answer by DA924x Wednesday, August 8, 2018 8:07 PM
    • Edited by DA924x Wednesday, August 8, 2018 8:08 PM
    Wednesday, August 8, 2018 8:07 PM