title: NHibernate create configuration provider
body: <p>We are trying to implement a cloud database solution using nhibernate. We are using Azure SQL Database and we are in troubles at the time of set the connection. As the Authentication keyword is not allowed on the connection string, the only way to create a connection is to provide an Access Token. This property is not available on nhibernate. We were advised to create our own connection provider in order to achieve this. Our connection provides is:</p>
  <pre><code>using Project.dataaccessobjects;
  using Project.security;
  using Microsoft.IdentityModel.Clients.ActiveDirectory;
  using NHibernate.Connection;
  using System;
  using System.Data.Common;
  using System.Data.SqlClient;
  using System.Threading.Tasks;
  namespace Project.connection
  {
      public partial class AzureSQLDatabase : DriverConnectionProvider
      {
          private string strSQLServer{ get; set; }
          private string strDatabase { get; set; }
          private string strTenantId { get; set; }
          private string strClientId { get; set; }
          private string strPassword { get; set; }
          public AzureSQLDatabase() : base()
          {
              strSQLServer = AzureKeyVaultDAO.getInstance().get(&quot;SQLServer&quot;);
              strDatabase = AzureKeyVaultDAO.getInstance().get(&quot;Database&quot;);
              strTenantId = AzureKeyVaultDAO.getInstance().get(&quot;TenantId&quot;);
              strClientId = AzureKeyVaultDAO.getInstance().get(&quot;ClientId&quot;);
              strPassword = AzureKeyVaultDAO.getInstance().get(&quot;Password&quot;);
          }
          private string accessToken()
          {
              const string ResourceUrl = &quot;https://database.windows.net/&quot;;
              string AuthorityUrl = $&quot;https://login.microsoftonline.com/{strTenantId}&quot;;
              AuthenticationContext objAuthenticationContext;
              Task&lt;AuthenticationResult&gt; objAuthenticationResult;
              ClientCredential objCredentials;
              objCredentials = new ClientCredential(strClientId, SecureText.getInstance().decrypt(strPassword));
              objAuthenticationContext = new AuthenticationContext(AuthorityUrl);
              objAuthenticationResult = objAuthenticationContext.AcquireTokenAsync(ResourceUrl, objCredentials);
              return objAuthenticationResult.Result.AccessToken;
          }
          public override DbConnection GetConnection(string connectionString)
          {
              DbConnection objConnection = new SqlConnection();
              try
              {
                  objConnection.ConnectionString = connectionString;
                  ((SqlConnection) objConnection).AccessToken = accessToken();
                  objConnection.Open();
              }
              catch (Exception)
              {
                  objConnection.Dispose();
                  throw;
              }
              return objConnection;
          }
      }
  }
  </code></pre>
  <p>Next is our HibernateUtil class</p>
  <pre><code>using Project.dataaccessobjects;
  using Project.entities;
  using NHibernate;
  using NHibernate.Cfg;
  using System.Collections.Generic;
  namespace Project.hibernate
  {
      public class HibernateUtil
      {
          private static ISessionFactory _sessionFactory;
          private static ISessionFactory SessionFactory
          {
              get
              {
                  if (_sessionFactory == null)
                  {
                      Configuration objConfiguration = new Configuration();
                      objConfiguration.SetProperties(properties());
                      objConfiguration.AddAssembly(typeof(Entity/Beam/Domain).Assembly);
                      _sessionFactory = objConfiguration.BuildSessionFactory();
                  }
                  return _sessionFactory;
              }
          }
          private static Dictionary&lt;string, string&gt; properties()
          {
              Dictionary&lt;string, string&gt; obj = new Dictionary&lt;string, string&gt;();
              obj.Add(&quot;connection.provider&quot;, &quot;Project.connection.AzureSQLDatabase&quot;);
              obj.Add(&quot;connection.connection_string&quot;, $&quot;Server = tcp:{AzureKeyVaultDAO.getInstance().get(&quot;SQLServer&quot;)},1433; Initial Catalog = {AzureKeyVaultDAO.getInstance().get(&quot;Database&quot;)}; Persist Security Info = False; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False&quot;);
              obj.Add(&quot;dialect&quot;, &quot;NHibernate.Dialect.MsSqlAzure2008Dialect&quot;);
              obj.Add(&quot;show_sql&quot;, &quot;true&quot;);
              return obj;
          }
          public static ISession OpenSession()
          {
              return SessionFactory.OpenSession();
          }
      }
  }
  </code></pre>
  <p>At objConfiguration.BuildSessionFactory() we get the following exception:</p>
  <blockquote>
  <p>NHibernate.HibernateException: 'Could not instantiate connection
  provider: Project.connection.AzureSQLDatabase' TypeLoadException:
  Could not load type Project.connection.AzureSQLDatabase. Possible
  cause: no assembly name specified.</p>
  </blockquote>
  <p>Do you know what are we missing/skipping?</p>