Alachisoft / NCache

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

Issue with NcacheQuery in .net core 2.2 #40

Closed Sunsikh closed 5 years ago

Sunsikh commented 5 years ago

Hi folks! NCacheQuery doesn't work correctly in .net core application with NuGet package "Alachisoft.NCache.OpenSource.Linq". If you install this package, Ncache doesn't allow you to use LINQ for queries data in cache because you will get this error: The type 'Cache' is defined in an assembly that is not referenced. You must add a reference to assembly 'Alachisoft.NCache.Web, Version=4.9.0.0, Culture=neutral, PublicKeyToken=cff5926ed6a53769' In a classic .net framework, everything works flawlessly. The workaround is to add DLL from sample application that going with Ncache: "%NCHOME%\samples\dotnetcore\NCacheLINQ\NCacheLINQ\lib\Alachisoft.NCache.Linq.dll" to project dependency and with that library, everything starts working. Can u fix this, pls?

namespace ConsoleAppCoreNCache { class Program { static void Main(string[] args) { var cache = NCache.InitializeCache("myCache"); cache.Clear();

        Add(cache);

        var query = new NCacheQuery<TestObject>(cache);

        var results = query.Where(x => x.OddFlag == true);

        foreach(var result in results)
        {
            Console.WriteLine($"Odd number: {result.Number}");
        }

        Console.WriteLine("Press any key...");
        Console.ReadKey();
    }

    static void Add(Cache cache)
    {
        for (int i = 0; i < 20; i++)
        {
            var key = $"{i}";

            cache.Insert(key,
                new TestObject
                {
                    Id = key,
                    Number = i,
                    OddFlag = i % 2 == 0 ? false : true
                });
        }
    }
}

[Serializable]
public class TestObject
{
    public string Id { get; set; }
    public int Number { get; set; }
    public bool OddFlag { get; set; }
}

}


- config.ncconf:
Brad-NCache commented 5 years ago

Hello Sunsikh,

Thank you for pointing out this issue to us and furnishing your application code so that we can narrow down the root cause, this was very helpful.

I have reproduced the scenario on my end and confirm that there is a version mismatch with NCache LINQ integration assembly that is shipped with NuGet package and this is why it is raising the error. Our engineering has published an updated NuGet Package Alachisoft.NCache.OpenSource.Linq (v 4.9.1.1) with correct version information that should work as expected in your environment.

You can install this Nuget Package from Visual Studio and use it in your application.

Here is the NuGet.org link to the updated NuGet package:

https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.Linq/4.9.1.1

Sunsikh commented 5 years ago

And it's worked! Thx you very much!

DAConsulting commented 5 years ago

I have noticed that referencing either version of the NCache.Linq packages causes InitializeCache to hang or otherwise fail when attempting to use a "partitioned" cache. This is reproducible by changing the cache used in the NCacheLINQ sample project from "myCache" to "myPartitionedCache".

I have not found any documentation indicating that NCache Linq can only be used with a "local" cache?

If anyone has a solution for this (using Linq with partitioned cache) or information as to why we cannot use Linq with a partioned cache, kindly let us know.

Thanks.

DAConsulting commented 5 years ago

I have noticed that referencing either version of the NCache.Linq packages causes InitializeCache to hang or otherwise fail when attempting to use a "partitioned" cache. This is reproducible by changing the cache used in the NCacheLINQ sample project from "myCache" to "myPartitionedCache"....

It appears that the NuGet packages for LINQ install local configurations, which was confusing the issue.

So the issue I mention above is probably not an issue.