question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get Sharing violation exception

See original GitHub issue

Hi James, I used MonkeyChache.FileStore 1.2.0-beta in my .NetStandard 2.0 Xamarin.forms project.

I got this exception when I try to call

 Barrel.Current.Exists(key);
System.IO.IOException: Sharing violation on path /data/user/0/com.xx.app/MonkeyCacheFS/idx.dat

Do you have any idea why it throw this exceptions? I can catch the exception and it works fine. Do you think it’s necessary to mention this in the document?

Thanks, Jesse

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
JMan7777commented, Jan 14, 2020

Hi,

I’m having the same issue on MonkeyCache.FileStore. I just moved from MonkeyCache.LiteDB to MonkeyCache.FileStore since I had performance issues if the cache was getting too big.

In MonkeyCache.LiteDB I never encountered any concurrent access problems from different threads but now I’m also getting the Sharing violation (without changing anything else in my code).

@jamesmontemagno Could you please modify MonkeyCache.FileStore to ensure that only one process accessing the underlying file at the same time.

Since my code is highly multi threaded I need to use a wrapper around MonkeyCache.FileStore accesses at the moment to ensure single access.

`public sealed class CustomBarrel : IBarrel { private CustomBarrel() { }

    private static readonly object padlock = new object();

    private static readonly Lazy<CustomBarrel> lazy = new Lazy<CustomBarrel>(() => new CustomBarrel());

    public static string ApplicationId
    {
        get { return Barrel.ApplicationId; }
        set { Barrel.ApplicationId = value; }
    }

    public static CustomBarrel Current
    {
        get
        {
            return lazy.Value;
        }
    }

    public void Add<T>(string key, T data, TimeSpan expireIn, string eTag = null, JsonSerializerSettings jsonSerializationSettings = null)
    {
        lock (padlock)
        {
            Barrel.Current.Add(key, data, expireIn, eTag, jsonSerializationSettings);
        }
    }

    public void Empty(params string[] key)
    {
        lock (padlock)
        {
            Barrel.Current.Empty(key);
        }
    }

    public void EmptyAll()
    {
        lock (padlock)
        {
            Barrel.Current.EmptyAll();
        }
    }

    public void EmptyExpired()
    {
        lock (padlock)
        {
            Barrel.Current.EmptyExpired();
        }
    }

    public bool Exists(string key)
    {
        lock (padlock)
        {
            return Barrel.Current.Exists(key);
        }
    }

    public T Get<T>(string key, JsonSerializerSettings jsonSettings = null)
    {
        lock (padlock)
        {
            return Barrel.Current.Get<T>(key, jsonSettings);
        }
    }

    public string GetETag(string key)
    {
        lock (padlock)
        {
            return Barrel.Current.GetETag(key);
        }
    }

    public DateTime? GetExpiration(string key)
    {
        lock (padlock)
        {
            return Barrel.Current.GetExpiration(key);
        }
    }

    public IEnumerable<string> GetKeys(CacheState state = CacheState.Active)
    {
        lock (padlock)
        {
            return Barrel.Current.GetKeys(state);
        }
    }

    public bool IsExpired(string key)
    {
        lock (padlock)
        {
            return Barrel.Current.IsExpired(key);
        }
    }
}`

But I think such mechanism should be in MonkeyCache.FileStore itself.

Thx a lot.

Markus

0reactions
chayceecommented, Dec 6, 2022

also happening to me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sharing violation IOException while reading and writing to ...
This is caused when you try to Read or Write a file you just created from a separate stream. Solving this is very...
Read more >
IOException: Sharing violation on path C
Im getting this error while I try loading my game. It worked before perfectly and then just giving me this error.
Read more >
How to Fix the Excel Sharing Violation Error - Layer Blog
A sharing violation refers to any attempt made by an application to access content that is being used by another. In Excel, this...
Read more >
Excel intermittently giving sharing violation error when ...
1. Open File Explorer with the Windows key + E · 2. Right-click the folder that includes the Excel file the sharing violation...
Read more >
IOException: Sharing violation - Forums | Moodkie Interactive
This occurs when the save file is being accessed by another program or process. For example, the user has the file open in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found