web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Connector Development
Suggested Answer

Custom Connector “Code” (C#) How to read Environment Variables for Custom Connector ?

(0) ShareShare
ReportReport
Posted on by 8
I’m using Custom Connector – Custom Code (C#) to perform AES-256 encryption/decryption in Power Platform. I tried to read an AES key from environment variables, but I’m getting a compile-time error.

Error : 
Failed to provision compute for custom code. Request failed with error
'Code: BadRequest. Message: script.csx(37,55): error CS0103: The name 'environmentvariables'
does not exist in the current context.'. The correlation Id is 'fd016ca4-92ce-43bd-baa3-e3cc8e5bc1ca'.
 
Code :
 
public class Script : ScriptBase
{
    public static string OperationForEncryption = "encrypt";
    public static string OperationForDecryption = "decrypt";
 
    public static byte[] Key = Encoding.UTF8.GetBytes(@environmentvariables("siti_AES_Key"));
    public static byte[] Iv = Encoding.UTF8.GetBytes("abcdef9876543210");
 
    public static string ContentKey = "content";
 
    public override async Task<HttpResponseMessage> ExecuteAsync()
    {
        HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
 
        if (this.Context.OperationId == OperationForEncryption)
        {
            var contentBody = await this.Context.Request.Content.ReadAsStringAsync();
            var ans = ThroughEncryptionProcess(contentBody);
            var jsonResponse = JsonConvert.SerializeObject(new { data = ans });
            response.Content = new StringContent(jsonResponse, Encoding.UTF8, "application/json");
        }
        else if (this.Context.OperationId == OperationForDecryption)
        {
            var content = this.Context.Request.Headers.GetValues(ContentKey).FirstOrDefault();
            var ans = ThroughDecryptionProcess(content);
            response.Content = new StringContent(ans, Encoding.UTF8, "application/json");
        }
        return response;
    }
 
    public static string ThroughEncryptionProcess(string contentBody) { /* ... */ }
    public static string ThroughDecryptionProcess(string encryptedContent) { /* ... */ }
}
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    52,857 Super User 2025 Season 2 on at
    Custom Connector “Code” (C#) How to read Environment Variables for Custom Connector ?
     
    That is not valid inside of any code outside of the platform itself. It is not an exposed "API".
     
    You are going to have to get the Environment variable directly from Dataverse itself or save it somewhere else to grab, or pass it in.
     
    But you cannot use that in your code no.
     

    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.

    Thank you!
    Sincerely, Michael Gernaey

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 803 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 314 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 253 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics