【问题标题】:VB .NET Microsoft.Owin.Hosting WebApp.Start gives nullReferenceExceptionVB .NET Microsoft.Owin.Hosting WebApp.Start 给出 nullReferenceException
【发布时间】:2020-12-14 01:34:08
【问题描述】:

这是我的代码:

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

异常发生

【问题讨论】:

  • 欢迎来到 StackOverflow。最好不要将错误信息作为图像包含在内——其他人无法搜索到它。最好将其包含为文本。
  • 调用本身看起来不错(Start 是一个 Shared 函数,所以它不需要实例,url 是非空的),所以我猜你是缺少 OWIN 需要的其他东西。
  • 嗨@Craig 我不知道我在这里做错了什么,因为如果我点击这个链接:codedigest.com/posts/2/… 我认为我在将代码转换为 VB 时做得很好,但我仍然得到一个错误。但是 C# 代码工作正常,可以在这个 repo 中看到:github.com/RoccoSen/OwinToWebAPI.git 我认为我在 VB 方面做错了

标签: vb.net exception owin nullreferenceexception


【解决方案1】:

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

【讨论】:

  • 感谢您的回答。但是我从这个解决方案中得到了编译时错误:“WebApp”类型的“使用”操作数必须实现“System.IDisposable”。第二个错误是:重载解析失败,因为没有“新”是可访问的。
  • 这可能指向正确的方向,但它不是这种情况下的正确语法。正如我在对该问题的评论中指出的那样,WebApp.Start 是一个Shared 例程,它返回一个实现IDisposable 的对象。
猜你喜欢
  • 2011-02-04
  • 2016-11-04
  • 1970-01-01
  • 2020-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多