The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Vault Extension Method

Hello,

I am trying to do that Vault Extension method with the following parameters:

[VaultExtensionMethod("GetAccessToken")]
public async Task<string> GetAccessTokenAsync(EventHandlerEnvironment env)
{

CSC_API_Client clt = new CSC_API_Client();

string access_token = await clt.OAuth2_Token("authorization_code", env.Input);

return access_token;
}

I need to create an async task to wait for the response from an external API client.

When I try to install the VAF, I have this error in event log:

System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
   at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
   at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
   at MFiles.VAF.VaultExtensionMethodInfo..ctor(MethodInfo methodInfo, Object instance, MFVaultAccess requiredVaultAccess, Boolean hasSeparateEventHandlerProxy, EventHandlerVaultUserIdentity vaultUserIdentity) in E:\GRB\FkpraJb5\0\libraries\vaf\src\MFiles.VAF\Core\MethodInfo.cs:line 252
   at MFiles.VAF.VaultApplicationBase.CreateVaultExtensionMethodInfo(MethodInfo methodInfo, Object instance, VaultExtensionMethodAttribute attribute) in E:\GRB\FkpraJb5\0\libraries\vaf\src\MFiles.VAF\Core\VaultApplicationBase.cs:line 2931
   at MFiles.VAF.VaultApplicationBase.RegisterVaultExtensionMethodHandler(MethodInfo method, Object instance, Vault vault) in E:\GRB\FkpraJb5\0\libraries\vaf\src\MFiles.VAF\Core\VaultApplicationBase.cs:line 2601
   at MFiles.VAF.VaultApplicationBase.RegisterHandlers[T](IMethodSource source, Action`3 registerAction, Vault vault) in E:\GRB\FkpraJb5\0\libraries\vaf\src\MFiles.VAF\Core\VaultApplicationBase.cs:line 2699
   at MFiles.VAF.VaultApplicationBase.RegisterMethodsFromSource(IMethodSource source, Vault vault) in E:\GRB\FkpraJb5\0\libraries\vaf\src\MFiles.VAF\Core\VaultApplicationBase.cs:line 2539
   at MFiles.VAF.VaultApplicationBase.LoadHandlerMethods(Vault vault) in E:\GRB\FkpraJb5\0\libraries\vaf\src\MFiles.VAF\Core\VaultApplicationBase.cs:line 2473
   at MFiles.VAF.VaultApplicationBase.InitializeImpl(Vault vault) in E:\GRB\FkpraJb5\0\libraries\vaf\src\MFiles.VAF\Core\VaultApplicationBase.cs:line 1600
   at MFiles.VAF.VaultApplicationBase.Initialize(Vault vaultSrc) in E:\GRB\FkpraJb5\0\libraries\vaf\src\MFiles.VAF\Core\VaultApplicationBase.cs:line 1186

Any idea on how to overcome this? In a console application it works as expected.

Parents
  • You cannot use await/async. It must be synchronous. You will need to use Task.Wait to await the async calls within your method. 

  • Hello Craig,

    Thank for pointing me to the right direction.

    My code now is:

     [VaultExtensionMethod("GetAccessToken",
             RequiredVaultAccess = MFVaultAccess.MFVaultAccessNone)]
            private string GetAccessToken(EventHandlerEnvironment env)
            {
                string code = env.Input;           
                string result = GetAccessTokenVEMAsync(code).Result;
                return result;
    
            }

    Where GetAccesTokenVEMAsync is:

     public async Task<string> GetAccessTokenVEMAsync(string code)
            {
    
                CSC_API_Client clt = new CSC_API_Client();
                //SysUtils.ReportInfoToEventLog(code);
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                string access_token = await clt.OAuth2_Token("authorization_code", code);
                return access_token;
            }

    And it is working as expected Slight smile

Reply
  • Hello Craig,

    Thank for pointing me to the right direction.

    My code now is:

     [VaultExtensionMethod("GetAccessToken",
             RequiredVaultAccess = MFVaultAccess.MFVaultAccessNone)]
            private string GetAccessToken(EventHandlerEnvironment env)
            {
                string code = env.Input;           
                string result = GetAccessTokenVEMAsync(code).Result;
                return result;
    
            }

    Where GetAccesTokenVEMAsync is:

     public async Task<string> GetAccessTokenVEMAsync(string code)
            {
    
                CSC_API_Client clt = new CSC_API_Client();
                //SysUtils.ReportInfoToEventLog(code);
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                string access_token = await clt.OAuth2_Token("authorization_code", code);
                return access_token;
            }

    And it is working as expected Slight smile

Children
No Data