Alachisoft / NCache

NCache: Highly Scalable Distributed Cache for .NET
http://www.alachisoft.com
Apache License 2.0
647 stars 123 forks source link

Initialization Error: CacheServerModerator threw an exception #7

Open ccrandall69 opened 7 years ago

ccrandall69 commented 7 years ago

We recently needed to upgrade our NCache version from 4.3 Express to 4.4 Open Source. After doing this, we are receiving an error when our application tries to check the health of the cache...

var cacheHealth = CacheManager.GetCacheHealth(cacheName);

This method call gives the following error: Message: An error has occurred. ExceptionMessage: The type initializer for 'Alachisoft.NCache.Management.CacheConfigManager' threw an exception. ExceptionType: System.TypeInitializationException StackTrace: at Alachisoft.NCache.Management.ServiceControl.NCacheRPCService..ctor(String server) at Alachisoft.NCache.Management.CacheServerModerator..cctor() InnerException: { Message: An error has occurred. ExceptionMessage: Missing installation folder information: ROOTKEY= Software\Alachisoft\NCache ExceptionType: Alachisoft.NCache.Runtime.Exceptions.ManagementException StackTrace: at Alachisoft.NCache.Management.CacheConfigManager.ScanConfiguration() at Alachisoft.NCache.Management.CacheConfigManager..cctor() } }

The \HKEY_LOCAL_MACHINE\Software\Alachisoft\NCache registry key looks correct: (Default)/REG_SZ/(value not set) DotNetInstallMode/REG_SZ/5 Http.Port/REG_DWORD/0x0000203b (8251) InstallDir/REG_SZ/C:\Program Files\NCache\ Platform/REG_SZ/x64 Tcp.Port/REG_DWORD/0x0000203a (8250)

Any idea what may cause this error?

Thank you!

basitanwer commented 7 years ago

Are you using the same application compiled on OpenSource Edition or is it a new one?

If you're using the same application can you please check if this is reproducible on a new installation and a new app?

ccrandall69 commented 7 years ago

This is the same application, however, it looks like it was still using the old 4.3 SDK. I upgraded the SDK to 4.4.0, in nuget, and I receive the error:

System.IO.FileNotFoundException was unhandled by user code HResult=-2147024894 Message=Could not load file or assembly 'Alachisoft.NCache.Management, Version=4.4.0.0, Culture=neutral, PublicKeyToken=cff5926ed6a53769' or one of its dependencies. The system cannot find the file specified. Source=Alachisoft.NCache.Web FileName=Alachisoft.NCache.Management, Version=4.4.0.0, Culture=neutral, PublicKeyToken=cff5926ed6a53769

This is on my local machine and I before upgrading to 4.4.0 I was able to replicate the error above that I was receiving in our development environment.

I'm in the process of debugging this latest error.

Thanks!

basitanwer commented 7 years ago

Just found out

CacheManager.GetCacheHealth

is not supported in OpenSource Edition. See the comparison chart here

But fret not, there is still a way to get your cache statistics. Going through the ListCache tool you can extract the necessary information you want about the NCache statistic.

Just add reference to Alachisoft.NCache.Management and Alachisoft.NCache.Common dlls and do the things that ListCache tool does. As a start do the following

NCacheRPCService NCache = new NCacheRPCService("");
ICacheServer cacheserver = NCache.GetCacheServer(new TimeSpan(0, 0, 10));
ConfiguredCacheInfo[] cacheInfo = cacheserver.GetAllConfiguredCaches();

ConfiguredCacheInfo info = cacheInfo.Single<ConfiguredCacheInfo>(c => c.CacheId.Equals("myPartitionedCache",StringComparison.InvariantCultureIgnoreCase));

You could get more information based on if the cache is running


if (info.IsRunning)
{
     cacheserver.GetCacheStatistics2(info.CacheId);
     // Get more information
}
1400co commented 7 years ago

im using the code like this

`private Cache InitializeCache(ISettings settings) { //var ncservice = new NCacheRPCService(settings.CacheIp, CacheConfigManager.NCacheTcpPort); var ncservice = new NCacheRPCService(""); var ncserver = ncservice.GetCacheServer(new TimeSpan(0, 0, 0, 30)); var defaultconfig = ncserver.GetCacheConfiguration("Cache"); defaultconfig.Name = settings.CacheName;

        if (!ncserver.IsCacheRegistered(settings.CacheName))
            ncserver.RegisterCache(settings.CacheName, defaultconfig, string.Empty, true, true);

        if (!ncserver.IsRunning(settings.CacheName))
            ncserver.StartCache(settings.CacheName);

        Cache cache = NCache.InitializeCache(settings.CacheName, new CacheInitParams()
        {
            ServerList = new CacheServerInfo[]
                {
                    new CacheServerInfo(settings.CacheIp, settings.CachePort)
                }
        });

        return cache;
    }`

in the line var ncservice = new NCacheRPCService(""); it trhows this exception: `ex.InnerException.Message: Missing installation folder information: ROOTKEY= Software\Alachisoft\NCache at Alachisoft.NCache.Management.CacheConfigManager.ScanConfiguration() at Alachisoft.NCache.Management.CacheConfigManager..cctor()

at Alachisoft.NCache.Management.CacheConfigManager.get_NCacheTcpPort() at Alachisoft.NCache.Management.ServiceControl.NCacheRPCService..ctor(String server)`