【问题标题】:Google Cloud Function Deployment Error "Function failed on loading user code. This is likely due to a bug in the user code."谷歌云函数部署错误“加载用户代码时函数失败。这可能是由于用户代码中的错误。”
【发布时间】:2021-11-06 05:24:25
【问题描述】:

我正在使用 Visual Studio 2019 创建一个谷歌云功能,我已经在 postman 中测试了代码并且它工作正常,我正在使用 cmd 使用以下命令进行部署:

gcloud functions deploy my-first-function --region=southamerica-east1 --entry-point dataVerification.FunctionVerifyData --runtime dotnet3 --trigger-http --allow-unauthenticated

但我收到以下错误:

不知道为什么会出现这个错误,代码是可以运行的,没有任何异常。

我正在使用的测试代码如下:

using Google.Cloud.Functions.Framework;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using System.IO;

namespace Data_Verification
{
    public class VerifyData : IHttpFunction
    {
        /// <summary>
        /// Logic for your function goes here.
        /// </summary>
        /// <param name="context">The HTTP context, containing the request and the response.</param>
        /// <returns>A task representing the asynchronous operation.</returns>
        public async Task HandleAsync(HttpContext context)
        {
            string body = await new StreamReader(context.Request.Body).ReadToEndAsync();

            await context.Response.WriteAsync(body + " ");
            await context.Response.WriteAsync(context.Response.StatusCode.ToString());
        }
    }
}

【问题讨论】:

  • 您有更多关于 Cloud Build 或 Cloud Logging 的详细信息吗?
  • 嗨,我设法解决了问题,正如我在下面的帖子中所说,我没有日志了,但是,我记得安装 .Net Core SDK 包时出错

标签: c# .net-core deployment google-cloud-functions


【解决方案1】:

哎呀,伙计们,我最终发现了错误,这是一件非常简单的事情。当我创建一个函数时,函数命名空间中的名称必须与我放在文件夹中的名称相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 2020-10-15
    • 2020-11-15
    • 2019-10-27
    • 1970-01-01
    • 2019-09-20
    • 2019-11-26
    相关资源
    最近更新 更多