user1946932
user1946932

Reputation: 600

Convert C# to VB.NET, Implements IHttpHandler?

From:

Visual Studio Not Displaying SVG image as background

I'm trying to convert:

public class SvgHandler : IHttpHandler
{

    public bool IsReusable
    {
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/svg+xml";
        context.Response.BinaryWrite(File.ReadAllBytes(context.Request.PhysicalPath));
        context.Response.End();
    }
}

to VB.NET.

My automatic conversion from most of the online converters is:

Imports System.Globalization
Imports System.IO
Imports System.Linq
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Security
Imports System.Text
'Imports System.Threading.Tasks
Imports Microsoft.VisualBasic

Public Class SvgHandler
    Implements IHttpHandler

    Public ReadOnly Property IsReusable() As Boolean
        Get
            Return False
        End Get
    End Property

    Public Sub ProcessRequest(ByVal context As HttpContext)

        context.Response.ContentType = "image/svg+xml"
        context.Response.BinaryWrite(File.ReadAllBytes(context.Request.PhysicalPath))
        context.Response.[End]()

    End Sub

End Class

However the Implements IHttpHandler has a squiggly blue underline with the message:

Compiler Error Message: BC30154: Class 'SvgHandler' must implement 'ReadOnly Property IsReusable() As Boolean' for interface 'System.Web.IHttpHandler'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers.

What should the correct VB.NET code be?

Upvotes: 0

Views: 504

Answers (1)

user1946932
user1946932

Reputation: 600

This compiles (as suggested automatically by VS2019):

Imports System.IO

Public Class SvgHandler
    Implements IHttpHandler
    Private ReadOnly Property IHttpHandler_IsReusable As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

    Private Sub IHttpHandler_ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest

        context.Response.ContentType = "image/svg+xml"
        context.Response.BinaryWrite(File.ReadAllBytes(context.Request.PhysicalPath))
        context.Response.[End]()

    End Sub

End Class

Upvotes: 1

Related Questions