Skip to content

Inline CSharp Script Code does not work with external nuget packages #1471

@AnthonyDobbelaere

Description

@AnthonyDobbelaere

Describe the Bug

When creating an inline Csharp script that references an external nuget package it does not fetch the required assembly files. The documentation states that a function.proj file needs to be provided with the package reference. Then the logic app should be restarted for the runtime to recognize the file and download the required assemblies. This does not happen.

Error:
The function 'execute_csharp_script_code.csx' failed with the error 'C# Script compilation failed with the following errors:'(3,1): error CS0006: Metadata file 'ClosedXML' could not be found (11,7): error CS0246: The type or namespace name 'ClosedXML' could not be found (are you missing a using directive or an assembly reference?) (69,35)

Plan Type

Standard

Steps to Reproduce the Bug or Issue

  1. Create workflow with a action execute c sharp script with external nuget package reference
  2. Add the required function.proj file in Logic app kudu workflow folder.
    site/wwwroot//workflow.json
    site/wwwroot//function.proj
  3. Restart Logic App
  4. Expected behaviour that the assemblies are being download from nuget.org. Does not happen

Workflow JSON

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "contentVersion": "1.0.0.0",
        "actions": {
            "excel": {
                "type": "Compose",
                "inputs": {
                    "attachmentContentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                    "attachmentContent": "UEsDBBQABgAIAAAAIQAAAAAAAAAAAAAAAAAJAAAAX3JlbHMvUEsDBBQABgAIAAAAIQAAAAAAAAAAAAAAAAATAAAAX3JlbHMvLnJlbHNQSwMEFAAGAAgAAAAhAAAAAAAAAAAAAAAAABAAAAB4bC9fcmVscy9QSwMEFAAGAAgAAAAhAAAAAAAAAAAAAAAAABQAAAB4bC9fcmVscy8uUEsDBBQABgAIAAAAIQAAAAAAAAAAAAAAAAATAAAAd29ya2Jvb2sueG1sUEsDBBQABgAIAAAAIQAAAAAAAAAAAAAAAAAYAAAAeGwvd29ya3NoZWV0cy9zaGVldDEueG1sUEsDBBQABgAIAAAAIQAAAAAAAAAAAAAAAAATAAAAeGwvc3R5bGVzLnhtbFBLAQIUABQABgAIAAAAIQAAAAAAAAAAAAAAAAAJAAAAAAAAAAAAAACkgQAAAABfcmVscy9QSwECFAAUAA YACAAAACEAAAAAAAAAAAAAAAAAEwAAAAAAAAAAAAAApIEcAAAAX3JlbHMvLnJlbHNQSwECFAAU AAYACAAAACEAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAACkgTAAAAAeGwvd29ya3NoZWV0cy9zaGVldDEueG1sUEsFBgAAAAAFAAUAmQAAAGIAAAAAAA=="
                },
                "runAfter": {}
            },
            "Execute_C#_script_code": {
                "type": "CSharpScriptCode",
                "inputs": {
                    "CodeFile": "execute_csharp_script_code.csx"
                },
                "runAfter": {
                    "excel": [
                        "SUCCEEDED"
                    ]
                }
            }
        },
        "outputs": {},
        "triggers": {
            "When_an_HTTP_request_is_received": {
                "type": "Request",
                "kind": "Http"
            }
        }
    },
    "kind": "Stateful"
}

Screenshots or Videos

No response

Additional context

c sharp script:

`
#r "Newtonsoft.Json"
#r "Microsoft.Azure.Workflows.Scripting"
#r "ClosedXML"
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.Workflows.Scripting;
using Newtonsoft.Json.Linq;
using System.Globalization;
using System.Xml.Linq;
using ClosedXML.Excel;

public static async Task Run(WorkflowContext context, ILogger log)
{
var excel = (await context.GetActionResults("excel").ConfigureAwait(false)).Outputs;
return ConvertExcelBytesToXml(excel.attachmentContent);
}

public static XDocument ConvertExcelBytesToXml(string excelBytes)
{
byte[] bytes = Convert.FromBase64String(excelBytes);
if (excelBytes == null || excelBytes.Length == 0)
{
throw new ArgumentException("Excel byte array is empty.");
}

using var stream = new MemoryStream(bytes);
using var workbook = new XLWorkbook(stream);

var wbNode = "Workbook";
var wsNode = "Worksheet";
var rowNode = "Row";
var cellNode = "Cell";


var xDoc = new XDocument(new XElement(wbNode));
var root = xDoc.Root;

foreach (var worksheet in workbook.Worksheets)
{
    var worksheetElement = new XElement(wsNode);
    root.Add(worksheetElement);
    worksheetElement.Add(new XAttribute("name", worksheet.Name));

    for (int rowIndex = worksheet.FirstRowUsed().RowNumber(); rowIndex <= worksheet.LastRowUsed().RowNumber(); rowIndex++)
    {
        var rowElement = new XElement(rowNode);
        worksheetElement.Add(rowElement);
        rowElement.Add(new XAttribute("rowIndex", rowIndex));

        for (int columnIndex = worksheet.FirstColumnUsed().ColumnNumber(); columnIndex <= worksheet.LastColumnUsed().ColumnNumber(); columnIndex++)
        {
            var cell = worksheet.Cell(rowIndex, columnIndex);
            var cellElement = new XElement(cellNode, GetCellValue(cell));
            rowElement.Add(cellElement);

            cellElement.Add(new XAttribute("address", cell.Address.ToString(XLReferenceStyle.A1)));

            if (cell.IsMerged())
            {
                cellElement.Add(new XAttribute("mergedCell", cell.MergedRange().RangeAddress.ToString(XLReferenceStyle.Default)));
            }
        }
    }
}
return new XDocument(root);

}

public static string GetCellValue(IXLCell cell)
{
DateTime dateTime = DateTime.Now;
if (cell.DataType == XLDataType.DateTime && DateTime.TryParse(cell.Value.ToString(), new CultureInfo("en-US"), DateTimeStyles.AssumeLocal, out dateTime))
{
return dateTime.ToString("dd-MM-yyyy");
}
return cell.Value.ToString();
}
`

function.proj file:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="ClosedXML" Version="0.105.0" /> </ItemGroup> </Project>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions