0

I am trying Proof of Concepts based on code at http://msdn.microsoft.com/en-us/library/windowsazure/gg618003. This cache is accesible if I use app.config settings. When I switched the application to use programatic configuration, I consistently get this error. I have already tried Azure cache programatically configuration fail to verify and many other solutions to no avail.

Here's my code snippet.

{code}

        String                              acsKey = "AcsKey removed intentionaly";
        DataCacheFactoryConfiguration       cacheFactoryConfiguration;
        DataCacheSecurity                   dataCacheSecurity;
        DataCacheServerEndpoint[]           serverEndpoints = new DataCacheServerEndpoint[1];
        SecureString                        secureAcsKey = new SecureString();

        serverEndpoints[0] = new DataCacheServerEndpoint("EndPont removed intentionaly", 22243);

        //
        // Create SecureString from string
        //
        foreach (char keyChar in acsKey)
        {
           secureAcsKey.AppendChar(keyChar);
        }
        secureAcsKey.MakeReadOnly();
        dataCacheSecurity  = new DataCacheSecurity(secureAcsKey);

        //
        // Initialize Factory Configuration
        //

        cacheFactoryConfiguration = new DataCacheFactoryConfiguration(); // This line throws exception. Note that the key is yet to be assigned to SecurityProperties as per documentation.
        cacheFactoryConfiguration.Servers = serverEndpoints;
        cacheFactoryConfiguration.SecurityProperties = dataCacheSecurity;

        _cacheFactory = new DataCacheFactory(cacheFactoryConfiguration);
        _cache = _cacheFactory.GetDefaultCache();

{code}

Community
  • 1
  • 1
Chetan
  • 184
  • 12
  • I just figured this out. I had used NuGet's installation instructions (cause the documentation says so). This adds a configuration entry that I did not realize was there. It had the templatized version of file and was causing problems. Once I removed it, the code started working fine. – Chetan Sep 11 '12 at 21:46

1 Answers1

0

Try passing all the params at creation and not post creation?

    var configFactory = new DataCacheFactoryConfiguration
                            {
                                Servers =
                                    new List<DataCacheServerEndpoint>
                                        {new DataCacheServerEndpoint(cacheServer, cachePort)},
                                SecurityProperties =
                                    new DataCacheSecurity(Encryption.CreateSecureString(cacheAuthorization),
                                                          true)
                            };
Igorek
  • 15,716
  • 3
  • 54
  • 92
  • I found the issue to be something different. I did not find Encryption.CreateSecureString anywhere. The snippet of code does work as well (once I fixed the app.config issue). – Chetan Sep 11 '12 at 21:47