"Could not load type 'System.Security.Cryptography.SHA256Cng' " in Azure Functions

Alexandre Von Mühlen 71 Reputation points
2021-03-31T21:20:45.167+00:00

Hi.

I'm Azure Functions for about an year, and today it started to give me the following error message:
Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

I use this function to start a Power BI Dataset and Dataflow refreshes.

In my requirements, I have these two entries:
'Az' = '5.'
'MicrosoftPowerBIMgmt' = '1.
'

To connect on Power BI, I'm using the "Connect-PowerBIServiceAccount" method.

Nothing has changed in this function.

Do you have any suggestion?

Thank you very much.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

4 answers

Sort by: Most helpful
  1. ChaitanyaNaykodi-MSFT 27,476 Reputation points Microsoft Employee Moderator
    2021-05-12T20:33:30.85+00:00

    Hello @Alexandre Von Mühlen , @bee911 , @Davis, Matthew , @Pablo Gómez Cruañes

    We received the update below from the team regarding fix for the issue.

    The root cause of the issue is the ADAL module incompatibility with .Net Core. To fix this, the PowerBi team will move to use the MSAL module instead of ADAL. The fix estimate is about 1 month and will be available at https://www.powershellgallery.com/packages/MicrosoftPowerBIMgmt. Please note that no change will be required on the Functions side.

    You can track the resolution here (https://github.com/microsoft/powerbi-powershell/issues/288)

    Current Work-around:
    Please follow the workaround described in here by "furmangg"
    https://github.com/microsoft/powerbi-powershell/issues/288#issuecomment-833177448 and https://github.com/microsoft/powerbi-powershell/issues/288#issuecomment-837118044

    Please let me know if there are any additional concerns.

    1 person found this answer helpful.
    0 comments No comments

  2. ChaitanyaNaykodi-MSFT 27,476 Reputation points Microsoft Employee Moderator
    2021-04-15T20:04:14.317+00:00

    Hello @Alexandre Von Mühlen & @bee911 , my sincere apologies for the delay and thank you for your patience throughout the process. The team did a detailed analyses of the backend logs and shared the observation made below.
    Possible cause of the issue:
    After comparing the logs from March 20th 2021 when the app was running fine below were the versions of the modules utilized.

    'Az' module version '5.6.0'
    MicrosoftPowerBIMgmt' version '1.0.946'
    and sub modules of MicrosoftPowerBIMgmt were of version '1.0.946'.

    We think when the issue started below were the versions installed

    'Az' module version '5.8.0'
    MicrosoftPowerBIMgmt' version '1.0.974'
    and sub modules of MicrosoftPowerBIMgmt were of version '1.0.974'.

    When the MicrosoftPowerBIMgmt module was pinned to 1.0.946 as suggested below were the versions installed

    MicrosoftPowerBIMgmt' version '1.0.946'
    but the sub modules of MicrosoftPowerBIMgmt still remained of version '1.0.974' which might have caused the issue.

    Suggested Mitigation Steps:

    To download all of the function app dependencies locally and then publish them with their app again. To achieve this you can follow the documentation mentioned here. Add the specific module to the Modules folder and set the managedDependency property to false in the root of the host.json file.

    Please let me know if there are any concerns, I will be glad to continue with our discussion.

    Additionally can you please share some additional details regarding the authentication mechanism used to connect via the Connect-PowerBIServiceAccount cmdlet so that the team can reproduce the error in our end, a code snippet of this mechanism will be great (You can share it as a private message above if you find that comfortable.) Thank you!


  3. Pablo Gómez Cruañes 6 Reputation points
    2021-04-22T17:09:59.963+00:00

    Same issue here, no changes, azure function just stopped working. My last successful execution was on 22/04/2021 and suddenly it does not runs anymore.

    I've been tinkering with depenecies but to no success.

    [edit: typo]

    0 comments No comments

  4. Alexandre Von Mühlen 71 Reputation points
    2021-05-07T18:43:14.91+00:00

    Hi everyone.

    Following the advice from @ChaitanyaNaykodi-MSFT , I've just finished to implement the workaround suggested by "niphlod" on this post:
    https://github.com/microsoft/powerbi-powershell/issues/288#issuecomment-832518621

    $modulePath = $Env:APPSETTING_POWERBI_PROFILE_MODULE_PATH  
    Import-Module $modulePath -usewindowspowershell -warningaction silentlycontinue  
      
    ...  
    Connect-PowerBIServiceAccount -Credential $credential  
    $token = Get-PowerBIAccessToken  
    ....  
    $headers = @{ "Authorization" = $token["Authorization"] }  
       
    # Power BI API call  
    $apihost = $Env:APPSETTING_POWERBI_API_HOST  
    $uri = $apihost + "groups/$workspaceID/datasets/$datasetID/refreshes"  
       
    Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -erroraction stop  
    

    Basically, you will have to import the last version of the "MicrosoftPowerBIMgmt.Profile" module, then you will be able to connect to Power BI.

    In my case, I had some problems, because in my code I was using for example the "Get-PowerBIWorkspace" method, that is implemented in the "MicrosoftPowerBIMgmt.Workspaces" module. I am receiving error when I tried to load this module.

    To solve this problem, I had to convert all my code to use calls with "Invoke-RestMethod".

    I think it is a very ugly workaround, but for now is working.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.