[Python] Why is my python Azure Function unable to load "file or module...

Discussão em 'Python' iniciado por Stack, Março 19, 2025.

  1. Stack

    Stack Membro Participativo

    I've been developing a python Azure Function and debugging locally for about a month now. Suddenly, the local debugging was unable to execute "func host start" and returns the below error:

    Unhandled exception. System.AggregateException: One or more errors occurred. (Unable to load one or more of the requested types.
    Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.)
    ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
    Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
    at System.Reflection.RuntimeModule.GetTypes()
    at Azure.Functions.Cli.ConsoleApp..ctor(String[] args, Assembly assembly, IContainer container)
    at Azure.Functions.Cli.ConsoleApp.RunAsync[T](String[] args, IContainer container)
    System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    File name: 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    File name: 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    File name: 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    File name: 'System.Security.Cryptography, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    --- End of inner exception stack trace ---
    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
    at System.Threading.Tasks.Task.Wait()
    at Azure.Functions.Cli.ConsoleApp.Run[T](String[] args, IContainer container)
    at Azure.Functions.Cli.Program.Main(String[] args)


    My Details:


    • Windows 11


    • Python: 3.11.9 from Windows Store


    • Azure Functions Extension: 1.16.3


    • Azure Functions Core Tools: 4.0.5907

      requirements.txt:

    azure-functions
    pymupdf


    I'm not sure why this started happening. Reboots don't fix it, and I'd like to avoid wiping my work laptop until I have to. I also tried repairing my VS Code installation and reinstalling core tools. This even happens with the HTTP Trigger example, with no edits made. Any help would be greatly appreciated, thank you!!

    I've tried:

    Rebooting -> didnt work

    Repair VS Code Installation -> didnt work Uninstall and Reinstall Azure Core Tools -> didnt work

    removed excess python version (3.12) -> no effect

    tried running an unchanged HTTP Trigger Example -> issue still occurs

    Putting System.Security.Cryptography and other variations within requirements.txt -> no effect

    I've located System.Security.Cryptography .dlls and don't see one identical to the module found - but I never changed anything in the directory and this worked a week or two ago...

    Continue reading...

Compartilhe esta Página