Skip to main content

I'm upgrading my site from Sitecore 8.1 to Sitecore 8.2, and one of the compile errors that I'm getting is

CS1503 Argument 3: cannot convert from 'long' to 'System.EventHandler<Sitecore.Caching.Generics.EntryRemovedEventArgs'

As I'm looking into this, I think that I remember reading thathow Sitecore completely changed how the cache is working in 8.2, and therefore I will need to change my code as well. Can someone provide an overview of what kind of changes I'll need to make to my code so that I can run on 8.2?

Edit

This class is based on the Sitecore.CachineCaching.CustomCache class. Here's the code that I'm having problems with:

    public void SetObject(string key, object content)
    {
        base.SetObject(key, content, EstimateObjectSize(content));
    }

    private long EstimateObjectSize(object obj)
    {
        long size = 0;
        try
        {
            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, obj);
                size = s.Length;
            }
        }
        catch(SerializationException)
        {
            // object cannot be serialized so just return 0
            size = 0;
        }
        return size;
    }

The code is complaining about the base.SetObject call (with the EstimateObjectSize) method. I understand that I need to change my object, and having read that document that Mark posted, I still am not sure what changes need to be done. It seems as if the SetObject method has changed from holding content to holding some sort of event, and I can't wrap my head around how this is supposed to work. I'm sorry for the vague/generic original post, I'll try to be more specific in the future.

Thanks for your help!

I'm upgrading my site from Sitecore 8.1 to Sitecore 8.2, and one of the compile errors that I'm getting is

CS1503 Argument 3: cannot convert from 'long' to 'System.EventHandler<Sitecore.Caching.Generics.EntryRemovedEventArgs'

As I'm looking into this, I think that I remember reading that Sitecore completely changed how the cache is working in 8.2, and therefore I will need to change my code as well. Can someone provide an overview of what kind of changes I'll need to make to my code so that I can run on 8.2?

Edit

This class is based on the Sitecore.Cachine.CustomCache class. Here's the code that I'm having problems with:

    public void SetObject(string key, object content)
    {
        base.SetObject(key, content, EstimateObjectSize(content));
    }

    private long EstimateObjectSize(object obj)
    {
        long size = 0;
        try
        {
            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, obj);
                size = s.Length;
            }
        }
        catch(SerializationException)
        {
            // object cannot be serialized so just return 0
            size = 0;
        }
        return size;
    }

The code is complaining about the base.SetObject call (with the EstimateObjectSize) method. I understand that I need to change my object, and having read that document that Mark posted, I still am not sure what changes need to be done. It seems as if the SetObject method has changed from holding content to holding some sort of event, and I can't wrap my head around how this is supposed to work. I'm sorry for the vague/generic original post, I'll try to be more specific in the future.

Thanks for your help!

I'm upgrading my site from Sitecore 8.1 to Sitecore 8.2, and one of the compile errors that I'm getting is

CS1503 Argument 3: cannot convert from 'long' to 'System.EventHandler<Sitecore.Caching.Generics.EntryRemovedEventArgs'

As I'm looking into this, I think that I remember reading how Sitecore completely changed the cache working in 8.2, and therefore I will need to change my code as well. Can someone provide an overview of what kind of changes I'll need to make to my code so that I can run on 8.2?

Edit

This class is based on the Sitecore.Caching.CustomCache class. Here's the code that I'm having problems with:

    public void SetObject(string key, object content)
    {
        base.SetObject(key, content, EstimateObjectSize(content));
    }

    private long EstimateObjectSize(object obj)
    {
        long size = 0;
        try
        {
            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, obj);
                size = s.Length;
            }
        }
        catch(SerializationException)
        {
            // object cannot be serialized so just return 0
            size = 0;
        }
        return size;
    }

The code is complaining about the base.SetObject call (with the EstimateObjectSize) method. I understand that I need to change my object, and having read that document that Mark posted, I still am not sure what changes need to be done. It seems as if the SetObject method has changed from holding content to holding some sort of event, and I can't wrap my head around how this is supposed to work. I'm sorry for the vague/generic original post, I'll try to be more specific in the future.

Thanks for your help!

Retagged
Link
Gatogordo
  • 20.3k
  • 2
  • 39
  • 100
Added syntax highlighting
Source Link
Richard Seal
  • 20.8k
  • 5
  • 44
  • 79
    public void SetObject(string key, object content)
    {
        base.SetObject(key, content, EstimateObjectSize(content));
    }

    private long EstimateObjectSize(object obj)
    {
        long size = 0;
        try
        {
            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, obj);
                size = s.Length;
            }
        }
        catch(SerializationException)
        {
            // object cannot be serialized so just return 0
            size = 0;
        }
        return size;
    }
    public void SetObject(string key, object content)
    {
        base.SetObject(key, content, EstimateObjectSize(content));
    }

    private long EstimateObjectSize(object obj)
    {
        long size = 0;
        try
        {
            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, obj);
                size = s.Length;
            }
        }
        catch(SerializationException)
        {
            // object cannot be serialized so just return 0
            size = 0;
        }
        return size;
    }
    public void SetObject(string key, object content)
    {
        base.SetObject(key, content, EstimateObjectSize(content));
    }

    private long EstimateObjectSize(object obj)
    {
        long size = 0;
        try
        {
            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, obj);
                size = s.Length;
            }
        }
        catch(SerializationException)
        {
            // object cannot be serialized so just return 0
            size = 0;
        }
        return size;
    }
    public void SetObject(string key, object content)
    {
        base.SetObject(key, content, EstimateObjectSize(content));
    }

    private long EstimateObjectSize(object obj)
    {
        long size = 0;
        try
        {
            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, obj);
                size = s.Length;
            }
        }
        catch(SerializationException)
        {
            // object cannot be serialized so just return 0
            size = 0;
        }
        return size;
    }
Loading
Added more detail in the original question
Source Link
Loading
deleted 1 character in body; edited tags
Source Link
Mark Cassidy
  • 25.4k
  • 7
  • 59
  • 117
Loading
Source Link
Loading