'loading Public Function Transfer() As HtmlDocument Dim sbResult As New StringBuilder Dim ctTransfer As New XslCompiledTransform Dim htmlReturn As HtmlDocument Using swHelper As New StringWriter(sbResult), wbContent As New WebBrowser ctTransfer.Load("blabla.xslt", Nothing, New XmlUrlResolver) ctTransfer.Transform("blublub.xml", Nothing, swHelper) wbContent.DocumentText = sbResult.ToString htmlReturn = wbContent.Document If IsNothing(wbContent.Document) Then MsgBox("hi") '<-- not triggered End Using Return htmlReturn End Function 'display Dim y As HtmlDocument = x.Transfer() If IsNothing(y.Body) Then MsgBox("hi") '<-- is being triggered MsgBox(y.Body) '<-- therefore this raises an exception