Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure functions 试图以与数组不兼容的类型访问元素。Azure函数应用程序错误_Azure Functions_Console Application - Fatal编程技术网

Azure functions 试图以与数组不兼容的类型访问元素。Azure函数应用程序错误

Azure functions 试图以与数组不兼容的类型访问元素。Azure函数应用程序错误,azure-functions,console-application,Azure Functions,Console Application,我正在尝试直接使用门户将我的控制台应用程序解决方案加载到Azure功能应用程序中。解决方案在我的本地VS2019上按预期运行,但在函数应用程序上加载了相同的解决方案,给出了“试图以与数组不兼容的类型访问元素”错误。 你能给我一些建议吗?我也试着用#r.“/Dllname.dll”加载所有必需的dll,但仍然收到相同的错误 #r "System.Data" #r "System.Configuration" #r "Newtonsoft.Json" #r "System.Web" #r "Micr

我正在尝试直接使用门户将我的控制台应用程序解决方案加载到Azure功能应用程序中。解决方案在我的本地VS2019上按预期运行,但在函数应用程序上加载了相同的解决方案,给出了“试图以与数组不兼容的类型访问元素”错误。 你能给我一些建议吗?我也试着用#r.“/Dllname.dll”加载所有必需的dll,但仍然收到相同的错误

#r "System.Data"
#r "System.Configuration"
#r "Newtonsoft.Json"
#r "System.Web"
#r "Microsoft.WindowsAzure.Storage"


#r "./Microsoft.Bot.Schema.dll"
#r "./Microsoft.Graph.Beta.dll"
#r "./Microsoft.Graph.Core.dll"
#r "./Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
#r "./Microsoft.Bot.Connector.dll"
#r "./RestSharp.dll"
#r "./Microsoft.SharePoint.Client.Runtime.dll"
#r "./Microsoft.SharePoint.Client.dll"
#r "./Microsoft.Rest.ClientRuntime.dll"
#r "./netstandard.dll"
#r "./System.Collections.dll"
// #r "./Microsoft.Extensions.Logging.dll"

using System;
using Microsoft.Graph;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Net.Http.Headers;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using Microsoft.SharePoint.Client;
using Microsoft.Rest.ClientRuntime;
using RestSharp;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq.Expressions;

更新:

从您的评论中,我知道您正在使用v1函数。与函数v2不同,函数v1程序集由
project.json
控制

比如说,

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.ProjectOxford.Face": "1.1.0"
      }
    }
   }
}
如果要使用自定义程序集,需要先上载它们。有关详细信息


原始答案:

如果您使用C#脚本处理function v2,请注意,您需要使用function.proj来安装软件包。就像包管理在本地服务器上工作一样

解决方案:

1.创建一个
函数.proj
文件

2.在此文件中写入要安装的软件包。


netcoreapp2.1

你能提供一些代码吗?我已经更新了这个问题,事实上,即使我删除了所有的代码,只是保持引用不动,但它给出了错误。据我所知,错误是由于dll不匹配,但不确定。您好,看起来您正在使用C#脚本。您是否已经在
project.json
ot
function.proj
中配置了程序集?如果您刚刚部署到Azure,应该没有问题。但如果您使用C#脚本,请注意它与VS2019在本地使用C#脚本不同。虽然它们看起来非常相似。在我的azure项目中没有名为function.proj的文件,但我有function.json,如下
{“bindings”:[{“type”:“timerTrigger”,“name”:“myTimer”,“schedule”:“0*****”,“direction”:“In”}],“disabled”:“false}
我没有使用dotnet核心,相反,我使用的是dotnet 4.6.1,包内引用是否需要添加我使用的所有引用?@MayureshJaiswal嗨,MayureshJaiswal。我可以问一下您现在使用的功能版本吗?你说你没有使用dotnetcore,那么它是v1函数吗?如果你使用的是v1函数,那么解决方案就会不同。是的,我使用的是v1函数v1@MayureshJaiswal好的,请稍等。将更新我的答案。@MayureshJaiswal我已经发布了关于使用crx时如何使用函数v1的官方文档。
 <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Google.Apis.Sheets.v4" Version="1.40.3.1679" />
    <PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
  </ItemGroup>
</Project>
#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

public static string DBConn = "123456";
public static ILogger Log = null;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    Log=log;  
    DBConn="MySQLSrvrConnectionString";
    try
    {
        string spreadsheetId = "MyGoogleSheetId";
        //SheetsService service = GetSheetService();
        //if(service!=null)
        //{
        //    DoSomethingFunc(GetInsertCommand(GetSheetVals(service,spreadsheetId)));
        //}
    }
    catch (Exception ex)
    {
        Log.LogInformation($"Error ({DateTime.Now.ToLongDateString()}): {ex.Message}");
    }
    finally
    {
        Log.LogInformation($"Function Completed at: {DateTime.Now.ToLongDateString()}");
    }
    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    return name != null
        ? (ActionResult)new OkObjectResult($"Hello, {name}")
        : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}