Get-AzureRmSnapshot throws error Get-AzureRmSnapshot : Method 'get_SerializationSettings' - azure

When trying to restore my azure VM from previous snapshot using powershell I get error:
Get-AzureRmSnapshot : Method 'get_SerializationSettings' in type
'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient'
from assembly 'Microsoft.Azure.Commands.ResourceManager.Common,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
does not have an implementation.

This is a known issue, documented by Microsoft.
The error indicates that the Azure Resource Manager modules and Az modules are loaded in the same session and those modules are not compatible with each other.
Remediation: Uninstall the conflicting modules. Either Azure Resource Manager modules or the Az modules
https://learn.microsoft.com/en-us/azure-stack/operator/azure-stack-powershell-install?view=azs-2008

Close powershell and try relauch. It fixed the issue.
Hope it help others who is facing the similar issue.

Related

Azure PowerShell SDK: Could not load file or assembly 'Azure.Storage.Queues' when Import-Module Az.Storage

I am getting the following error when running: Import-Module Az.Storage. I am not what the problem is.
PS error: System.Management.Automation.CommandNotFoundException: The 'New-AzStorageAccount' command was found in the module 'Az.Storage', but the module could not be loaded due to the following error: [Could not load file or assembly 'Azure.Storage.Queues, Version=12.12.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'.]
For more information, run 'Import-Module Az.Storage'.
---> System.Management.Automation.CmdletInvocationException: Could not load file or assembly 'Azure.Storage.Queues, Version=12.12.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'.
---> System.IO.FileLoadException: Could not load file or assembly 'Azure.Storage.Queues, Version=12.12.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'.
at System.Management.Automation.Runspaces.InitialSessionState.Bind_LoadAssemblies(ExecutionContext context)
at System.Management.Automation.Runspaces.InitialSessionState.Bind(ExecutionContext context, Boolean updateOnly, PSModuleInfo module, Boolean noClobber, Boolean local, Boolean setLocation)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion, Nullable`1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors)
--- End of inner exception stack trace ---
The error "The 'New-AzStorageAccount' command was found in the module 'Az.Storage', but the module could not be loaded due to the following error: [Could not load file or assembly 'Azure.Storage.Queues'" usually occurs if the required dependencies are not installed for the Az.Storage module.
I tried to reproduce the same in my environment and got the results like below:
Import-Module Az.Storage
I am able to install the Az.Storage module without any error:
I created an Azure Storage Account by using the below command:
New-AzStorageAccount -ResourceGroupName RGName -Name StorageAccName -Location Location -SkuName Standard_GRS
To resolve the error, please try the below:
The Azure PowerShell Az module must be installed in order to use the Az.Storage module.
Check whether you are using the latest version of the Az module and if not, update the module version:
Install-Module -Name az
Update-Module -Name Az
Get-InstalledModule -Name Az
You can also try updating the Az.Storage module like below:
Update-Module -Name Az.Storage
Get-InstalledModule -Name Az.Storage
If still the issue persists, re-install the Az Module and check.
Uninstall-Module -Name az
Install-Module -Name az
Check the PowerShell version too. Restart the PowerShell Window after the Uninstall and Install operations.
Reference:
az.storage load errors Azure/azure-powershell ยท GitHub

Azure and AzureRM Powershell Module Conflicts

I'm setting up an Azure DevOps self hosted pipeline agent. We have some legacy cloud services, so we need the "old" Azure powershell module that targets the service management API. We also obviously use Azure Resource Manager, so either the AzureRM or the new Az module is also required.
We currently have the Azure module version 5.3.0 and AzureRM module version 6.13.1 being installed using the following commands:
Install-Module -Name Azure -RequiredVersion 5.3.0 -AllowClobber -Scope AllUsers -Force
Install-Module -Name AzureRM -RequiredVersion 6.13.1 -AllowClobber -Scope AllUsers -Force
The problem we're encountering is that, depending on the order these modules are imported, we will get script failures. If, for example, the order of import is Azure followed by AzureRM, we get the following error:
Import-Module : The following error occurred while loading the
extended type data file: Error in TypeData
"Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer":
The TypeConverter was ignored because it already occurs. Error in
TypeData
"Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer":
The member SerializationDepth is already present. Error in TypeData
"Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache":
The member PropertySerializationSet is already present. Error in
TypeData
"Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache":
The member SerializationMethod is already present. Error in TypeData
"Microsoft.Azure.Commands.Common.Authentication.AuthenticationStoreTokenCache":
The member PropertySerializationSet is already present. Error in
TypeData
"Microsoft.Azure.Commands.Common.Authentication.AuthenticationStoreTokenCache":
The member SerializationMethod is already present. Error in TypeData
"Microsoft.Azure.Commands.Profile.Models.PSAzureContext": The member
SerializationDepth is already present. Error in TypeData
"Microsoft.Azure.Commands.Profile.Models.PSAzureProfile": The member
SerializationDepth is already present. At C:\Program
Files\WindowsPowerShell\Modules\AzureRm\6.13.1\AzureRM.psm1:81 char:1
+ Import-Module AzureRM.Profile -RequiredVersion 5.8.2 -Global
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
You can see this in the following screen shot:
But if import AzureRm first, followed by Azure, it appears to work fine:
The problem is, we don't control the order of the imports when using existing pipeline tasks built by Microsoft and others. We're getting failures deploying our cloud services due to the fact the cloud service deployment task built by MS happens to import Azure first.
Lastly, I tried simply not installing the old Azure module, hoping that AzureRM "came with" what it would need to handle some service management API tasks, but it does not. If I try do a deployment without the Azure module installed, we get the error:
Certificate based authentication is not supported. Azure PowerShell
module is not found.
So it appears the legacy module is required, and yet it conflicts.
This appears to be caused by the order of installation. Flipping the order from Azure then AzureRm to AzureRm then Azure resolved the issue. So the following install commands do not result in the problem:
Install-Module -Name AzureRM -RequiredVersion 6.13.1 -AllowClobber -Scope AllUsers -Force
Install-Module -Name Azure -RequiredVersion 5.3.0 -AllowClobber -Scope AllUsers -Force
It appears the root cause is that the Azure module, if installed first, will always install the most recent version of AzureRm.profile. This appears to be caused by the Azure.Storage module, which has a dependency on AzureRm.profile.
If you install the Azure module first, it will install AzureRm.profile version 5.8.3. When you then install AzureRm, it has a dependency of AzureRm.profile as well, but it will ignore the fact that you already have AzureRm.profile v5.8.3 installed and install AzureRm.profile v5.8.2. I believe this is because while the Azure module has a dependency on AzureRm.profile, the AzureRm module includes AzureRm.profile.
When Import-Module is called for Azure first, it loads v5.8.3 of the AzureRm.profile module, as it will always load the most recent version by design. When, however, AzureRm itself is loaded, it tries to load the version IT came with (v5.8.2), and this fails due to the type error noted in the question.
If you install AzureRM before Azure, it prevents this from happening. Since when the Azure module is being installed it sees there is already a version of AzureRm.profile that satisfies its dependency (or, more specifically, satisfies the dependency that Azure.Storage has), it doesn't install AzureRm.profile again. This leaves only the version that AzureRm was packaged with, and everything is fine.
Lastly, for an existing "broken" environment, running this command resolved the problem:
Uninstall-Module -Name AzureRM.profile -RequiredVersion 5.8.3

Azure KeyVault nuget package issues

When I installing Azure.KeyVault package version 3 alpha, I'm getting the following runtime exception:
Could not load file or assembly 'Microsoft.Azure.KeyVault, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
Downgrading this package to latest stable 2.3.2 causes another error:
Here is my package list with dependencies:
Any ideas or workaround on this?
Seems like the problem was inside v2 runtime:
https://github.com/Azure/azure-functions-host/issues/2854
My decision was to turn roll back to v1 Functions, cause I found another issues during the KeyVault implementation by this article:
https://learn.microsoft.com/en-us/azure/app-service/app-service-managed-service-identity
Here is the issue:
https://github.com/Azure/azure-functions-host/issues/2852

Azure Function Nuget Cache restore failing with "The user name or password is incorrect."

I have an Azure Function I deploy as a part of an ARM template. This Azure Function references a few external .NET DLLs. I have added the reference to these DLLs in the project.json file:
project.json:
{
"frameworks": {
"net46": {
"dependencies": {
"Microsoft.IdentityModel.Clients.ActiveDirectory":"3.13.8",
"Newtonsoft.Json": "10.0.2",
"Microsoft.CrmSdk.CoreAssemblies" : "8.2.0.2"
}
}
}
}
When I click run, the Nuget Cache restore is kicked off. It fails with "The user name or password is incorrect."
The strange thing is the Nuget Packages are being copied to the Functions Nuget cache correctly, but the project.lock.json file is failing to be created. It appears the username / password error is thrown after the Nuget cache restore completes and when Azure tries to write the project.lock.json file. The compile then fails as the project.lock.json file is not created.
2017-11-14T21:06:34.892 Restoring packages.
2017-11-14T21:06:34.892 Starting NuGet restore
2017-11-14T21:06:36.239 Function started (Id=1340feea-174d-4bee-97f2-e06afc2e2d6e)
2017-11-14T21:06:36.239 Package references have been updated.
2017-11-14T21:06:36.239 Restoring packages.
2017-11-14T21:06:36.239 Starting NuGet restore
2017-11-14T21:06:36.955 Restoring packages for D:\home\site\wwwroot\ProvisionUserToCRM\project.json...
2017-11-14T21:06:37.456 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.clients.activedirectory/index.json
2017-11-14T21:06:37.486 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.clients.activedirectory/3.13.8/microsoft.identitymodel.clients.activedirectory.3.13.8.nupkg
2017-11-14T21:06:37.705 CACHE https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
2017-11-14T21:06:37.705 CACHE https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.2/newtonsoft.json.10.0.2.nupkg
2017-11-14T21:06:37.800 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/index.json
2017-11-14T21:06:37.800 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/8.2.0.2/microsoft.crmsdk.coreassemblies.8.2.0.2.nupkg
2017-11-14T21:06:37.881 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel/index.json
2017-11-14T21:06:37.881 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel/6.1.7600.16394/microsoft.identitymodel.6.1.7600.16394.nupkg
2017-11-14T21:06:38.002 Installing Microsoft.IdentityModel 6.1.7600.16394.
2017-11-14T21:06:38.362 Installing Microsoft.CrmSdk.CoreAssemblies 8.2.0.2.
2017-11-14T21:06:38.939 Restoring packages for D:\home\site\wwwroot\ProvisionUserToCRM\project.json...
2017-11-14T21:06:39.113 Installing Newtonsoft.Json 10.0.2.
2017-11-14T21:06:39.255 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.clients.activedirectory/index.json
2017-11-14T21:06:39.284 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel.clients.activedirectory/3.13.8/microsoft.identitymodel.clients.activedirectory.3.13.8.nupkg
2017-11-14T21:06:39.455 CACHE https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
2017-11-14T21:06:39.455 CACHE https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.2/newtonsoft.json.10.0.2.nupkg
2017-11-14T21:06:39.470 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/index.json
2017-11-14T21:06:39.470 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.crmsdk.coreassemblies/8.2.0.2/microsoft.crmsdk.coreassemblies.8.2.0.2.nupkg
2017-11-14T21:06:39.490 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel/index.json
2017-11-14T21:06:39.502 CACHE https://api.nuget.org/v3-flatcontainer/microsoft.identitymodel/6.1.7600.16394/microsoft.identitymodel.6.1.7600.16394.nupkg
2017-11-14T21:06:39.642 Installing Microsoft.IdentityModel.Clients.ActiveDirectory 3.13.8.
2017-11-14T21:06:41.211 Installing Microsoft.IdentityModel 6.1.7600.16394.
2017-11-14T21:06:42.367 Installing Microsoft.CrmSdk.CoreAssemblies 8.2.0.2.
2017-11-14T21:06:46.398 Installing Microsoft.IdentityModel.Clients.ActiveDirectory 3.13.8.
2017-11-14T21:06:49.197 Installing Newtonsoft.Json 10.0.2.
2017-11-14T21:06:52.171 The user name or password is incorrect.
2017-11-14T21:06:52.189
2017-11-14T21:06:52.189
2017-11-14T21:06:52.189 Packages restored.
2017-11-14T21:06:52.500 Script for function 'ProvisionUserToCRM' changed. Reloading.
2017-11-14T21:06:52.813 run.csx(2,18): error CS0234: The type or namespace name 'IdentityModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
2017-11-14T21:06:52.813 run.csx(3,8): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Does anyone know why this error is displayed? It seems to come intermittently for me. Seems like a bug in Azure Functions. Are there any known work arounds?
I found enabling 'Slots' preview feature on Azure Functions actually resolves this issue, but 'Slots' will not work for me as they are not compatible with Azure Logic Apps.
Looks like Microsoft has confirmed this is a bug in Azure Functions
https://github.com/Azure/Azure-Functions/issues/590
The only work around I am aware of is to:
enable slots feature
keep re deploying your ARM template until it works
(I did not verify this) but I suspect it would work if you manually generated and dropped the lock file to the Functions file system. You could generate the lock file locally with visual studio. I suspect this would work because from what I observed is the NuGet packages seem to be restored correctly, and the error comes during the write of the JSON file. The compiler must reference the lock file rather than the actual NuGet cache when trying to compile (hence why the error is coming even though the DLL actually exists).

Entity framework assembly issue

When i am try to use bulkinsert method on EF by using entityframework.bulinsert dll getting Error message _"Could not load file or assembly 'EntityFramework.MappingAPI, Version=5.0.0.6, Culture=neutral, PublicKeyToken=7ee2e825d201459e' or one of its dependencies. The system cannot find the file specified".
It simply means the assembly is missing in your project AND/OR 'EntityFramework.MappingAPI, Version=5.0.0.6, is missing in your References.
Download the 'EntityFramework.MappingAPI, Version=5.0.0.6, from HERE
Extract the dll's from the folder and add a reference to the appropriate one that is version 5, from your solution.
OR
To install EntityFramework.MappingAPI, run the following command in the Package Manager Console
PM> Install-Package EntityFramework.MappingAPI -Version 5.0.0.6
This will install and automatically add a reference to it.``

Resources