Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.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
从VisualStudio部署azure函数和类库_Azure_Azure Functions_C# 3.0 - Fatal编程技术网

从VisualStudio部署azure函数和类库

从VisualStudio部署azure函数和类库,azure,azure-functions,c#-3.0,Azure,Azure Functions,C# 3.0,我使用VisualStudio开发了azure函数,该函数使用外部类库,并且该函数还有一些包。当我部署到azure function app并运行该功能时,我收到错误500内部服务器错误 我还需要部署类库和包吗?如果是,如何部署 请帮我做这个 using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; using Mic

我使用VisualStudio开发了azure函数,该函数使用外部类库,并且该函数还有一些包。当我部署到azure function app并运行该功能时,我收到错误500内部服务器错误

我还需要部署类库和包吗?如果是,如何部署

请帮我做这个

  using Microsoft.Azure.WebJobs;
  using Microsoft.Azure.WebJobs.Extensions.Http;
  using Microsoft.AspNetCore.Http;
  using Microsoft.Extensions.Logging;
  using Newtonsoft.Json;
 using IronPython.Hosting;//for DLHE
 using Microsoft.Scripting.Hosting;//provides scripting abilities comparable to batch files
using System.Diagnostics;
using IronPython.Compiler;
using System.Text;
using Microsoft.Scripting;
using DatasetLibrary;
using System.Data;

 namespace ExecutePyCode
   {
public static class Function1
{
    [FunctionName("Function1")]
    public static int Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string name = req.Query["name"];

        int result = 0;

        var engine = Python.CreateEngine();
        var scope = engine.CreateScope();
        //try
        //{

        var compilerOptions = (PythonCompilerOptions)engine.GetCompilerOptions();
        //compilerOptions.Module = IronPython.Runtime.ModuleOptions.co
        //ErrorSink errorSink = null;
        //ErrorListener errorListener = new ErrorSinkProxyListener(errorSink);
        //var scriptSource = engine.CreateScriptSourceFromFile(@"C:\Nidec\PythonScript\download_nrlist.py", Encoding.UTF8, Microsoft.Scripting.SourceCodeKind.File);
        //var compiledCode = scriptSource.Compile();
        //compiledCode.Execute(scope);
        //engine.ExecuteFile(@"C:\Nidec\PythonScript\download_nrlist.py", scope);

        //get function and dynamically invoke
        //var calcAdd = scope.GetVariable("CalcAdd");
        //result = calcAdd(34, 8); // returns 42 (Int32)
     
       //get values from external class library
        DatasetValues datasetValues = new DatasetValues();
        DataTable dt = datasetValues.GetDatasetValues();
        for (int i = 0; i <= dt.Rows.Count - 1; i++)
        {
            for (int j = 0; j <= dt.Columns.Count - 1; j++)
            {
                Console.WriteLine(dt.Rows[i][j]);

            }
        }

        return result;
    }
}
使用Microsoft.Azure.WebJobs;
使用Microsoft.Azure.WebJobs.Extensions.Http;
使用Microsoft.AspNetCore.Http;
使用Microsoft.Extensions.Logging;
使用Newtonsoft.Json;
使用IronPython.Hosting//对于DLHE
使用Microsoft.Scripting.Hosting//提供与批处理文件相当的脚本编写能力
使用系统诊断;
使用IronPython.Compiler;
使用系统文本;
使用Microsoft.Scripting;
使用数据库;
使用系统数据;
命名空间执行代码
{
公共静态类函数1
{
[功能名称(“功能1”)]
公共静态整型运行(
[HttpTrigger(AuthorizationLevel.Function,“get”,“post”,Route=null)]HttpRequest请求,
ILogger日志)
{
LogInformation(“C#HTTP触发器函数处理了一个请求。”);
字符串名称=请求查询[“名称”];
int结果=0;
var engine=Python.CreateEngine();
var scope=engine.CreateScope();
//试一试
//{
var compilerOptions=(PythonCompilerOptions)engine.GetCompilerOptions();
//compilerOptions.Module=IronPython.Runtime.ModuleOptions.co
//ErrorSink ErrorSink=null;
//ErrorListener ErrorListener=新的ErrorSinkProxyStener(errorSink);
//var scriptSource=engine.CreateScriptSourceFromFile(@“C:\Nidec\PythonScript\download\u nrlist.py”,Encoding.UTF8,Microsoft.Scripting.SourceCodeKind.File);
//var compiledCode=scriptSource.Compile();
//compiledCode.Execute(范围);
//ExecuteFile(@“C:\Nidec\PythonScript\download\nrlist.py”,范围);
//获取函数并动态调用
//var calcAdd=scope.GetVariable(“calcAdd”);
//result=calcAdd(34,8);//返回42(Int32)
//从外部类库获取值
DatasetValues DatasetValues=新的DatasetValues();
DataTable dt=datasetValues.GetDatasetValues();

对于(int i=0;i500错误无助于解决此问题,您需要检查azure函数的特定错误。您可以使用application insights获取详细信息错误。函数必须配置相应的application insights,然后才能在门户上查看日志

因此,您需要将应用程序洞察配置为功能应用程序,如下所示:

然后你的功能应用程序将重新启动

当然,您也可以到kudu查看:

首先,转到高级工具,然后单击“转到”

然后,在您进入kudu后,单击调试控制台->命令->日志文件->应用程序->函数->您的触发器名称。您将在那里找到日志文件


如果您基于linux操作系统,在转到kudu之后,只需单击“日志流”(linux的消费计划不支持这一点).

项目的库和包在project.json中定义,并在您将函数部署到Azure时自动安装。

您需要首先检查错误。您基于什么操作系统?WIndows或linux?500错误无助于解决此问题,您需要检查Azure函数的特定错误。此处有问题是否与部署一起部署?是否需要将外部调用库与azure函数一起部署?是否可以转到日志以检查特定错误?您可以使用application insights或kudu。我已在Visual Studio中创建了azure函数,其中是project.json?是否需要手动添加?在Visual Studio中查找解决方案中的依赖项->程序包explorerProject.json在哪里?我在解决方案中找不到任何地方。在Visual Studio中不会看到任何project.json,只会看到dependencies->Packages下的所有包依赖项