Hi Divakar,
Can you please make sure Nuget packages are also updated. I am able to connect CRM Services from Azure Functions based on two different approaches :

public static async Task<IOrganizationService> OpenDynamicsCRMConnectionAsync(ILogger log)
{
try
{
log.LogInformation($"Trying to Connect to CRM Instance at: {DateTime.Now}");
IOrganizationService organizationService = null;
// Create Dynamics CRM Connection ....................................
string ClientID = System.Configuration.ConfigurationManager.AppSettings["CRMClientID"].ToString();
string ClientSecret = System.Configuration.ConfigurationManager.AppSettings["CRMClientSecret"].ToString();
string Resource = System.Configuration.ConfigurationManager.AppSettings["Resource"].ToString();
string Authority = System.Configuration.ConfigurationManager.AppSettings["CRMAuthorize"].ToString();
log.LogInformation($"CRMClientID: {ClientID}");
//log.Info($"CRMClientSecret: {ClientSecret}");
log.LogInformation($"Resource: {Resource}");
log.LogInformation($"CRMAuthorize: {Authority}");
AuthenticationResult _authResult;
AuthenticationContext authContext = new AuthenticationContext(Authority);
ClientCredential credentials = new ClientCredential(ClientID, ClientSecret);
_authResult = await authContext.AcquireTokenAsync(Resource, credentials);
string Authtoken = _authResult.AccessToken;
// log.LogInformation($"Authtoken: {Authtoken}");
log.LogInformation($"Authtoken Generated Successfully");
string strCRMServiceURL = System.Configuration.ConfigurationManager.AppSettings["CRMServiceURL"].ToString();
Uri serviceUrl = new Uri(Resource + strCRMServiceURL.ToString());
log.LogInformation($"serviceUrl :" + serviceUrl.ToString());
using (OrganizationWebProxyClient sdkService = new OrganizationWebProxyClient(serviceUrl, false))
{
sdkService.HeaderToken = Authtoken;
organizationService = (IOrganizationService)sdkService;
//Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
//log.Info($"userid: {userid.ToString()}");
}
return organizationService;
//IOrganizationService organizationService = null;
//ClientCredentials clientCredentials = new ClientCredentials();
//clientCredentials.UserName.UserName = Environment.GetEnvironmentVariable("CRMAPPUserID").ToString();
//clientCredentials.UserName.Password = Environment.GetEnvironmentVariable("CRMAPPUserIDPwd").ToString();
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//string strCRMOrgURL = Environment.GetEnvironmentVariable("CRMOrgURL").ToString();
//organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri(strCRMOrgURL), null, clientCredentials, null);
//if (organizationService != null)
//{
// Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
// log.LogInformation($"userid: {userid.ToString()}");
//}
}
catch (Exception ex)
{
log.LogError($"Error Description CRM Connection: {ex.Message.ToString()}");
throw new System.Exception("CRM Connection Issue - " + ex.Message.ToString());
}
}
public static IOrganizationService OpenDynamicsCRMConnection_UnitTesting(ILogger log)
{
IOrganizationService organizationService = null;
try
{
log.LogInformation($"Trying to Connect to CRM Instance at: {DateTime.Now}");
// Create Dynamics CRM Connection ....................................
//string strCRMAPPUserID = System.Configuration.ConfigurationManager.AppSettings["CRMAPPUserID"].ToString();
//string strCRMAPPUserIDPwd = System.Configuration.ConfigurationManager.AppSettings["CRMAPPUserIDPwd"].ToString();
//string strCRMOrgURL = System.Configuration.ConfigurationManager.AppSettings["CRMOrgURL"].ToString();
//log.LogInformation($"strCRMAPPUserID: {strCRMAPPUserID}");
//log.LogInformation($"strCRMAPPUserIDPwd: {strCRMAPPUserIDPwd}");
//log.LogInformation($"strCRMOrgURL: {strCRMOrgURL}");
//ClientCredentials clientCredentials = new ClientCredentials();
//clientCredentials.UserName.UserName = strCRMAPPUserID;
//clientCredentials.UserName.Password = strCRMAPPUserIDPwd;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri(strCRMOrgURL), null, clientCredentials, null);
//if (organizationService != null)
//{
// Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
// log.LogInformation($"userid: {userid.ToString()}");
//}
// Create Dynamics CRM Connection ....................................
string CRMOAuthConnectionString = System.Configuration.ConfigurationManager.AppSettings["CRMOAuthConnection"].ToString();
log.LogInformation($"CRMOAuthConnection: {CRMOAuthConnectionString}");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
CrmServiceClient crmServiceClient = new CrmServiceClient(CRMOAuthConnectionString);
WhoAmIResponse whoAmIResponse = crmServiceClient.Execute(new WhoAmIRequest()) as WhoAmIResponse;
organizationService = crmServiceClient;
if (organizationService != null)
{
Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
log.LogInformation($"userid: {userid.ToString()}");
}
return organizationService;
}
catch (Exception ex)
{
log.LogError($"Error Description CRM Connection: {ex.Message.ToString()}");
throw new System.Exception("CRM Connection Issue - " + ex.Message.ToString());
}
}
Sample format from config file :
"CRMClientID": "*******-****-****-*********",
"CRMClientSecret": "******************",
"Resource": "https://******.crm.dynamics.com",
"CRMAuthorize": "">login.microsoftonline.com/.../authorize",
"CRMServiceURL": "/xrmservices/2011/organization.svc/web?SdkClientVersion=9.1",
"CRMOAuthConnection": "AuthType = OAuth; Url = 'https://******.crm.dynamics.com'; Username = '*******'; Password = '******'; AppId = 51f81489-12ee-4a9e-aaae-a2591f45987d; RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Never",