Open palmsey opened 5 years ago
I was able to resolve this by adding an "InstallDir" app setting. It looks like NCache is supposed to try to read this from System.Environment.CurrentDirectory
, which returns the IIS Express path instead of the project path when running in IIS Express. Using System.AppDomain.CurrentDomain.BaseDirectory
would be more accurate.
I couldn't find any mention of the "InstallDir" setting in the documentation.
Hi @palmsey
NCache always looks in the application bin folder first for the "Client.ncconf" file and if it does not find it there then it will go search for it in the NCache installation directory at NCache/Config path in case of installation. The issue you are referring to is specific to web apps deployed in IIS server that always checks for config files from the "insetsrv" folder by default
Here are some options you can try to resolve this in your environment,
Option 1:
You can use the CacheInitParams in your application when initializing the cache. This will take away any dependencies on client.ncconf file and you can control client side configurations programmatically. I am sharing more details on this below. CacheInitParams class allows a developer to configure the cache properties directly by code and NCache will then use the properties specified in code rather than checking the config file. A sample code is as follows:
CacheInitParams params = new CacheInitParams();
params.BindIP = "20.200.21.10"
params.CommandRetries = 5;
You can specify all client side properties that can be found with the documentation of the CacheInitParams class.
Option 2:
Here are steps that you can follow to read client.ncconf from a custom path when using Alachisoft Nuget package.
Go to the Windows Registry editor by typing "regedit" in the Windows run command.
Expand HKEY_LOCAL_MACHINE in the left pane of the editor and then right-click on SOFTWARE and add new key titled "Alachisoft".
Right-click on "Alachisoft" that you have just created and add new key titled "NCache".
Right-click on "NCache", click on the "New" tab in the drop down list and select "String Value".
Right-click on the new item you see in the right-hand pane and rename it "InstallDir".
Now right-click on "InstallDir" item and select "Modify".
In the resulting pop-up dialog box, write the custom path on your client machine where you will want your application to read client.ncconf file from. For our purposes, lets say the custom path is "D:\NCache"
Assuming your custom path is "D:\NCache", go to D:, create a new folder NCache and within the NCache folder, create a new folder titled "config". Add your client.ncconf file in this folder
Registry looks like this: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Alachisoft\NCache\InstallDir.
Your path to the client.ncconf file will look like this in the Windows Explorer address bar: D:\NCache\config.
Now, if you restart your server, the web app should be able to read from client.ncconf as expected.
I hope this helps.
@Kal-Alachisoft thanks. CacheInitParams may work for us, I will try that out. I would rather avoid modifying the registry on our servers and development machines.
@Kal-Alachisoft I tried using CacheInitParams and removed my "InstallDir" app setting. I'm using the params in the InitializeCache call, like this:
var cache = NCache.InitializeCache(Configuration.NCacheName, cacheParams);
When I run the application, I get an error on that line:
An error occurred while reading client.ncconf. The type initializer for 'Alachisoft.NCache.Common.AppUtil' threw an exception.
It seems like even when you specify CacheInitParams NCache is looking for the config file, and will throw an error if it can't find it.
Hi @palmsey , the CacheInitParams removes that dependency completely and should not be referring to the config file at all. Please confirm are you still having this issue?
Hi @Kal-Alachisoft, i'm using CacheInitParams in a ASP.NET MVC 5 project with sucess but in another project with WCF host service WEB i have the problem.
Hi @palmsey, can you please share with us a working sample with which the issue is reproduced?.
@palmsey I met exactly the same issue. Please check your bin folder if "ncregistry.dll" is there.
copy the file there if it isn't there.
When calling
NCache.InitializeCache("myCacheName")
in my ASP.NET project I'm getting this exception:An error occurred while reading client.ncconf. The type initializer for 'Alachisoft.NCache.Common.AppUtil' threw an exception.
Stack trace:
I've installed NCache 4.6.3 and the Open Source SDK NuGet package. The NCache service is running.
listcaches
shows I have a local cache running. I've tried editing permissions on client.ncconf to allow anyone to read/modify, both on the config file at the root of my web project and in the NCache installation folder. I've tried using the inproc cache "myCache" that is mentioned in the readme.txt that comes with the NuGet package too, but I keep getting the same error.What am I missing?