Join our community!

Get everything you need to start developing EPiServer solutions.

Null reference in File management / Global Files / VersioningFileSummary

April 28 2009, 11:23

When I try to open Global Files in File management Action Window I get a System.NullReferenceException on EPiServer.Web.Hosting.Versioning.VersioningFileSummary..ctor(FileItem file, FileOperations fileOp).

My setup is two servers with EPiServer 5.2.375.133 installed. Both joined to same domain. VPP files are stored on a third server in the same domain. AppDomain user is a domain account with modify permissions on the fileshare. Both servers use the same database. Remote events are configured for cache invalidation.

All worked fine until yesterday. The problem started after I uploaded an image, cropped it and saved it with a new name and then deleted the new cropped file. During the delete operation/request there was some kind of performance related problem within the environment. After the delete operation I always get the exception described above when I try to browse Global Files in File management. The VPP for Global Files is a EPiServer.Web.Hosting.VirtualPathVersioningProvider with default configuration.

The uploaded file and the cropped file still exist on the fileshare. The filename of the files also exists in the tblItems table, but the pkID is not the same as the guid on the fileshare. When viewing the site in viewmode, images from global files can be viewed.

There seams to be one or two files miss referenced in the VPP. Anyone knows how to fix this? And should this ever happen?


  • February 28 2011, 18:04
    Content is edited

    Hi Marthin, were you able to resolve this issue because I am also facing a similar issue?

  • February 28 2011, 21:36

    I have had a simular issue once. It was some files in the VPP that was created, but didn't exists.

    I used this code to fix the problem

            protected void Button12_Click(object sender, EventArgs e)
            {
                StartIndexOnItemLit.Text = "";
                 StringBuilder builder=new StringBuilder();
                 VirtualPathHandler instance = VirtualPathHandler.Instance;
                    
                foreach (var a in VirtualPathHandler.Instance.VirtualPathProviders.Keys)
                {
                    if (a is VirtualPathUnifiedProvider)
                    {
    
                        var dir = instance.GetDirectory((a as VirtualPathUnifiedProvider).VirtualPathRoot, true);
    
                        foreach (var element in dir.Children)
                        {
                            CheckItem(builder, element);
                        }
                    }
    
                }
                StartIndexOnItemLit.Text="<ul>"+builder.ToString()+"</ul>";
                // Itera.Cms5Provider.AddToIndexer.Current.AddToIndex(StartIndexOnItem.Text, true, false);
            }
    
            private void CheckItem(StringBuilder builder, object element)
            {
                if (element is UnifiedDirectory)
                {
                    CheckDir((element as UnifiedDirectory), builder);
                }
                if (element is UnifiedFile)
                {
                    CheckFil((element as UnifiedFile), builder);
                }
            }
            void CheckDir(UnifiedDirectory dir, StringBuilder builder)
            {
                try
                {
                    builder.AppendLine("<ul>");
                    foreach (var a in dir.Children)
                    {
                        CheckItem(builder, a);
                    }
                    builder.AppendLine("</ul>");
                }
                catch (System.Exception error)
                {
                    builder.AppendLine(dir.Name+" "+dir.VirtualPath+" "+error.Message+" "+error.StackTrace);
                }
            }
            void CheckFil(UnifiedFile fil,StringBuilder builder)
            {
                try
                {
                    var a = fil.Summary;
                }
                catch (Exception error)
                {
                    
                    builder.AppendLine("<li>deleting file since source don't exists " + fil.VirtualPath + "</li>");
                    fil.Delete();
                }
            }

        

  • March 9 2011, 9:33

    Awesome! I had the exact same problem with the VersioningFileSummary nullreference. This code helped me resolving this issue, thank you.

  • March 9 2011, 12:16

    you are welcome. Took myself some time to understand why. In my case it was a FileCreate event that throw an error

  • December 21 2011, 9:30

    Good work Anders. This saved me alot of time. Thanks.

  • December 21 2011, 10:10

    Thanks, happy that I could be of help :)

  • Ted
    January 29 2013, 10:24

    Anders, thanks a lot for sharing this! Saved me a lot of (unnecessary) work! :) Cheers!

  • February 18 2013, 15:27

    Hi Anders,

    I got a similar error but I wonder if you could explaon some more abput where you use the code you posted?

    Best regards,

    Carl

  • Ted
    February 18 2013, 15:49

    Carl, in my case I added an admin plugin with a button - and then added an event handler for that button's click event to execute Anders' code.

     

    he reason for the inconsistencies in my case was that I was trying to set file properties before I had written data to the file.