I need to add some nuget packages to the azure function. While trying to add a 'function.proj' file, getting an error as follows,
2019-07-12T07:52:13.177 [Information] System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
2019-07-12T07:52:13.177 [Information] at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
2019-07-12T07:52:13.903 [Information] at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
2019-07-12T07:52:13.904 [Information] at System.Environment.SetEnvironmentVariableCore(String variable, String value, EnvironmentVariableTarget target)
2019-07-12T07:52:13.904 [Information] at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
2019-07-12T07:52:13.905 [Information] at Internal.Runtime.Augments.EnvironmentAugments.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
2019-07-12T07:52:13.905 [Information] at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
2019-07-12T07:52:13.905 [Information] at Microsoft.DotNet.Cli.Utils.EnvironmentProvider.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
2019-07-12T07:52:13.906 [Information] at Microsoft.DotNet.ShellShim.WindowsEnvironmentPath.AddPackageExecutablePathToUserPath()
2019-07-12T07:52:13.906 [Information] at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
2019-07-12T07:52:13.906 [Information] at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel, IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)
2019-07-12T07:52:13.907 [Information] at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
2019-07-12T07:52:13.907 [Information] at Microsoft.DotNet.Cli.Program.Main(String[] args)
Try to create a 'function.proj' file and add some nuget packages to it.
After adding the above, nuget packages should get installed and show compilation succeeded message in the log.
Throwing a "System.UnauthorizedAccessException: Attempted to perform an unauthorized operation." exception in the log.
any solution?
@abinayasekar93 I was able to solve this by, instead of writing the Azure function in the portal directly, creating it in Visual Studio, adding the NuGet package like any usual local project and publishing the function to Azure.
@feresg Was there any additional files that Visual Studio uploaded in addition to the function.proj file that was already created?
@ethanbayliss when writing the function inside Visual Studio then publishing to Azure instead of the portal, I can only access the function in read-only mode and the only visible file is function.json
I've replicated this error on a new function and an existing function that was previously relying on nuget packages to work. Both functions were in different azure tenancies as well.
Function: https://bw...er.azurewebsites.net
ID: Id=de6f...f8e7
Runtime version: 2.0.12562.0 (~2)
I should also add that when attempting to retrieve packages via Nuget, the error does not occur unless the function.proj has been edited since last run. (adding whitespace anywhere in function.proj works) But since the nuget never successfully executes for me, the package is never retrieved and importing it fails.
@abinayasekar93 I was able to solve this by, instead of writing the Azure function in the portal directly, creating it in Visual Studio, adding the NuGet package like any usual local project and publishing the function to Azure.
@feresg I am able to solve this by using Visual studio instead of Azure portal.
Same problem here, trying to follow https://dotnetthoughts.net/resizing-images-using-azure-functions/ and it fails with the same error
@fabiocav and @brettsam - This issue is easy to reproduce, it feels like a regression?
2019-07-17T22:39:51.432 [Information] Restoring packages.
2019-07-17T22:39:51.451 [Information] Starting packages restore
2019-07-17T22:39:52.073 [Information] System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
2019-07-17T22:39:52.073 [Information] at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
2019-07-17T22:39:52.074 [Information] at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
2019-07-17T22:39:52.074 [Information] at System.Environment.SetEnvironmentVariableCore(String variable, String value, EnvironmentVariableTarget target)
2019-07-17T22:39:52.074 [Information] at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
2019-07-17T22:39:52.075 [Information] at Internal.Runtime.Augments.EnvironmentAugments.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
2019-07-17T22:39:52.075 [Information] at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
2019-07-17T22:39:52.075 [Information] at Microsoft.DotNet.Cli.Utils.EnvironmentProvider.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
2019-07-17T22:39:52.075 [Information] at Microsoft.DotNet.ShellShim.WindowsEnvironmentPath.AddPackageExecutablePathToUserPath()
2019-07-17T22:39:52.076 [Information] at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
2019-07-17T22:39:52.076 [Information] at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel, IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)
2019-07-17T22:39:52.077 [Information] at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
2019-07-17T22:39:52.081 [Information] at Microsoft.DotNet.Cli.Program.Main(String[] args)
2019-07-17T22:39:52.124 [Information] Packages restored.
If the steps on the docs are failing as described, yes, looks like a regression. Did you happen to see the specific operation that was restricted in the logs?
If the steps on the docs are failing as described, yes, looks like a regression. Did you happen to see the specific operation that was restricted in the logs?
@fabiocav There are no other specific information available in the logs except the above mentioned one.
Sorry if that wasn鈥檛 clear, but that was a question for @mhoeger . E identified the issue yesterday and we鈥檙e investigating a solution. Will keep this issue open to track. Thanks again for reporting!
@fabiocav - The message that popped up was "rejected file path access" for dotnet.exe, but it's not more specific beyond that!
That, with the other details you've found, tells us what is happening. The .NET CLI is attempting to write to a read only location in recent releases, and that is causing the issue. We're working to get a fix out ASAP.
While we work on a permanent fix, a known mitigation is to set the following app setting in your Function App:
Name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
Value: 1
Again, apologies for the issue. We'll have a permanent fix in place as soon as possible.
Fix has been checked-in and is being deployed as part of this release
https://github.com/Azure/app-service-announcements/issues/188
Please use https://github.com/Azure/app-service-announcements-discussions/issues/105 for discussions related to the release.
I am trying to create azure function in Portal and even adding the project.json file with all the dependencies i am getting error : "the type or namespace name azure does not exist in the namespace microsoft". Anything i am missing??
@bombshot - project.json is for V1 apps, is this a V2 app (if it's newly created, it will be)?
https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#using-nuget-packages
@mhoeger - Yes, It's a V2 app.
Issue is resolved, Thanks a lot 馃槉
Most helpful comment
While we work on a permanent fix, a known mitigation is to set the following app setting in your Function App:
Name:
DOTNET_SKIP_FIRST_TIME_EXPERIENCEValue: 1
Again, apologies for the issue. We'll have a permanent fix in place as soon as possible.