You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Visual Studio 2015开发VB Web Forms网站遇BC36645编译错误求助

Fixing BC36645 Error in Visual Studio 2015 (VB Web Forms)

Hey Eva-Lotta, let's get this BC36645 error sorted out for you! This error pops up when the Visual Basic compiler can't automatically figure out the generic type parameter (TResult) for Task.FromResult(). It's a common issue when the type of the value you're passing into FromResult isn't clear to the compiler, or when you haven't explicitly told it what type of Task you're returning.

Here are straightforward fixes to resolve this:

1. Explicitly specify the generic type parameter

The simplest fix is to tell the compiler exactly what TResult should be by adding Of [YourType] to the FromResult call.

For example, if you're returning a string value, instead of:

Return Task.FromResult("Hello World")

Write this:

Return Task.FromResult(Of String)("Hello World")

If you're returning a custom object (like a Customer class), specify that type instead:

Return Task.FromResult(Of Customer)(myCustomerObject)

2. Handle cases where you're returning Nothing

If you're passing Nothing into FromResult, the compiler has zero context to guess the type. You must specify the expected type explicitly here.

Instead of:

Return Task.FromResult(Nothing)

Use:

Return Task.FromResult(Of YourExpectedType)(Nothing)

Replace YourExpectedType with the actual type your method is supposed to return (e.g., Integer, Product, etc.).

3. Match the method's return type

Double-check that the type you specify in FromResult matches the return type of your method. For example, if your method is declared like this:

Public Async Function GetUserAsync() As Task(Of User)

Your return statement should explicitly use Of User to align with the method's return type:

Return Task.FromResult(Of User)(currentUser)

Full Example

Here's a before-and-after to make it concrete:

Broken Code (causes BC36645):

Public Function GetProductNameAsync() As Task(Of String)
    ' Compiler can't infer the TResult type
    Return Task.FromResult("Wireless Headphones")
End Function

Fixed Code:

Public Function GetProductNameAsync() As Task(Of String)
    ' Explicitly tell compiler we're returning a Task(Of String)
    Return Task.FromResult(Of String)("Wireless Headphones")
End Function

The core issue here is that Visual Basic's type inference needs a little extra help with Task.FromResult sometimes—by explicitly specifying the generic type, you remove the ambiguity and let the compiler build your solution successfully.

内容的提问来源于stack exchange,提问作者Eva-Lotta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:58:47