VB .NET Microsoft.Owin.Hosting WebApp.Start提供nullReferenceException

问题描述

这是我的代码

Imports Microsoft.Owin.Hosting
Imports System

Module Program
    Sub Main(args As String())
        Const url As String = "http://localhost:9001"
        
        Using WebApp.Start(url)
            Console.WriteLine("Server started at:" & url)
            Console.ReadLine()
        End Using
    End Sub
End Module

发生异常

As the error shows I am getting a null reference exception here don't know why

解决方法

您的Using语句语法错误。它应该类似于变量声明:

Imports Microsoft.Owin.Hosting
Imports System

Module Program
    Sub Main(args As String())
        Const url As String = "http://localhost:9001"
        
        Using wa As New WebApp
            wa.Start(url)
            Console.WriteLine("Server started at:" & url)
            Console.ReadLine()
        End Using
    End Sub
End Module

更多信息here