You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'Add-Type' doesn't work in applications that host powershell #9587
Add-Type depends on the reference assemblies shipped with pwsh. The reference assemblies are not bundled with PowerShell SDK NuGet packages, so Add-Type doesn't work for applications that host PowerShell.
Reacted by TylerLeonhardt, Rain Sallow (/u/ta11ow), Rabbit, Francisco Gamino and Dan Thompson
I can confirm that this issue is there in the latest version of Powershell core 6 / azure functions and is a blocker for us. Is there a known work-around to get this working on azure functions or perhaps an estimated ETA of when we think this may be addressed?
In my scenario, I am loading a community module for cosmosdb ( https://www.powershellgallery.com/packages/CosmosDB/3.2.4.376) inside an azure powershell function. This module uses a custom type definition which yields an error when ran in azure functions only:
[6/18/2019 3:39:54 PM] ERROR: Unable to find type [CosmosDB.ContextToken].
[6/18/2019 3:39:54 PM] Result: ERROR: Unable to find type [CosmosDB.ContextToken].
Exception: Unable to find type [CosmosDB.ContextToken].
Stack: at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
this is the custom type definition as per the community module
if (-not ([System.Management.Automation.PSTypeName]'CosmosDB.Context').Type)
{
$typeDefinition = @'
namespace CosmosDB {
public class ContextToken
{
public System.String Resource;
public System.DateTime TimeStamp;
public System.DateTime Expires;
public System.Security.SecureString Token;
}
public class BackoffPolicy
{
public System.Int32 MaxRetries;
public System.String Method;
public System.Int32 Delay;
}
public class Context
{
public System.String Account;
public System.String Database;
public System.Security.SecureString Key;
public System.String KeyType;
public System.String BaseUri;
public CosmosDB.ContextToken[] Token;
public CosmosDB.BackoffPolicy BackoffPolicy;
}
namespace IndexingPolicy {
namespace Path {
public class Index {
public System.String dataType;
public System.String kind;
}
public class IndexRange : CosmosDB.IndexingPolicy.Path.Index {
public readonly System.Int32 precision = -1;
}
public class IndexHash : CosmosDB.IndexingPolicy.Path.Index {
public readonly System.Int32 precision = -1;
}
public class IndexSpatial : CosmosDB.IndexingPolicy.Path.Index {
}
public class IncludedPath
{
public System.String path;
public CosmosDB.IndexingPolicy.Path.Index[] indexes;
}
public class ExcludedPath
{
public System.String path;
}
}
public class Policy
{
public System.Boolean automatic;
public System.String indexingMode;
public CosmosDB.IndexingPolicy.Path.IncludedPath[] includedPaths;
public CosmosDB.IndexingPolicy.Path.ExcludedPath[] excludedPaths;
}
}
namespace UniqueKeyPolicy {
public class UniqueKey {
public System.String[] paths;
}
public class Policy
{
public CosmosDB.UniqueKeyPolicy.UniqueKey[] uniqueKeys;
}
}
}
'@
Add-Type -TypeDefinition $typeDefinition
}
$PSVersionTable
----------------------
Name Value
---- -----
PSVersion 6.2.1
PSEdition Core
GitCommitId 6.2.1
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
-------------------------------------------------
func --version
2.7.1373
Alex Campos (@invisibleaxm) yep... that won't work today. Based on the code you've shown, it'd be very easy to convert those to PowerShell classes and things might just work...
but yeah this issue needs some work to be done in PowerShell which is actually quite difficult to solve elegantly.
Activity
TylerLeonhardt commentedon May 13, 2019
As ^ declares, Dongbo originally discovered this in Azure Functions - where I think folks will use Add-Type a fair bit at least.
vexx32 commentedon May 30, 2019
Admit it, you just want a PSWordCloud Azure function endpoint 😂
invisibleaxm commentedon Jun 18, 2019
I can confirm that this issue is there in the latest version of Powershell core 6 / azure functions and is a blocker for us. Is there a known work-around to get this working on azure functions or perhaps an estimated ETA of when we think this may be addressed?
In my scenario, I am loading a community module for cosmosdb ( https://www.powershellgallery.com/packages/CosmosDB/3.2.4.376) inside an azure powershell function. This module uses a custom type definition which yields an error when ran in azure functions only:
[6/18/2019 3:39:54 PM] ERROR: Unable to find type [CosmosDB.ContextToken].
[6/18/2019 3:39:54 PM] Result: ERROR: Unable to find type [CosmosDB.ContextToken].
Exception: Unable to find type [CosmosDB.ContextToken].
Stack: at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
this is the custom type definition as per the community module
TylerLeonhardt commentedon Jun 18, 2019
Alex Campos (@invisibleaxm) yep... that won't work today. Based on the code you've shown, it'd be very easy to convert those to PowerShell classes and things might just work...
but yeah this issue needs some work to be done in PowerShell which is actually quite difficult to solve elegantly.
jnevins-gcm commentedon Sep 1, 2019
any news on this? kind of a deal killer for using Powershell Core