Reputation: 178
I am new to Azure Functions but am attempting to call a c# file and method from the function. The "Run.csx" file itself is saying it is inaccessible due to the security level.
Azure run file:
using System;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
Integration.Run.ImportRosters(
log: s => log.Info(s),
connectionString: "conString",
siteID: 5,
nowUtc: DateTime.UtcNow,
ActualDays: 7,
RosterDays: 7
);
log.Info($"Import Roster Data function executed at: {DateTime.Now}");
}
And its calling this c# function:
namespace Integration
{
public static class Run
{
private static readonly TimeZoneInfo NewZealand = TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time");
public static void ImportRosters(
Action<string> log,
string connectionString,
int siteID,
DateTime nowUtc,
int actualDays,
int rosterDays
)
{
var adminDatabase = new HospoIQ_AdminDBContext();
var settings = adminDatabase.Settings.ToList();
var localDateTime = TimeZoneInfo.ConvertTimeFromUtc(nowUtc, NewZealand);
log($"Roster Data import function executed at: {localDateTime}");
var sqlConnection = new SqlConnection(connectionString);
I am in the belief that it is an error with my code on the Azure side as it doesn't even reach my c# code.
Error Message:
[Error] Function compilation error
2018-02-25T21:31:07.467 [Error] run.csx(10,5): error CS0149: Method name expected
2018-02-25T21:31:07.467 [Error] run.csx(11,33): error CS0122: 'Run' is inaccessible due to its protection level
2018-02-25T21:31:07.526 [Error] Exception while executing function:
Functions.ImportRosterData. Microsoft.Azure.WebJobs.Script: Script compilation failed.2018-02-25T21:31:07.698 [Error] Function completed (Failure, Id=08508394-4d6b-4cb0-a9e7-9479a017df05, Duration=289ms)
Upvotes: 1
Views: 859
Reputation: 9722
I‘m not 100% sure, but I think that the error means, that the static class Run
was inaccessible, not the Run
method of your function.
According to this source you’ll have to load your .csx file with the #load
directive in order to use it
#load "integration.csx"
Upvotes: 1
Reputation: 35144
You have a number of problems in your code sample:
load
directive in Run.csx
ActualDays
vs actualDays
)Run
not to confuse it with Run
of the FunctionBelow is a complete working example that you should base your implementation on.
Integration.csx
:
public static class Integration
{
private static readonly TimeZoneInfo NewZealand = TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time");
public static void ImportRosters(
Action<string> log,
string connectionString,
int siteID,
DateTime nowUtc,
int actualDays,
int rosterDays
)
{
var localDateTime = TimeZoneInfo.ConvertTimeFromUtc(nowUtc, NewZealand);
log($"Roster Data import function executed at: {localDateTime}");
}
}
Run.csx
:
#load "Integration.csx"
using System;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
Integration.ImportRosters(
log: s => log.Info(s),
connectionString: "conString",
siteID: 5,
nowUtc: DateTime.UtcNow,
actualDays: 7,
rosterDays: 7
);
log.Info($"Import Roster Data function executed at: {DateTime.Now}");
}
Upvotes: 4