Search code examples
c#imageresizer

Resolving Implement IMultiInstancePlugin after Nuget reinstall


Using .Net 4.6.2.

I loaded an old project from source control to add a new images page.

Image pages are kept in their respective folders, so I simply copied the functionality of "folder2015" to "folder2016" and ran the same code:

private void DisplayImages(string path) {
    var dir = new DirectoryInfo(path);
    var files = dir.GetFiles("DSC*.JPG");
    var sb = new StringBuilder("<table>");
    var td_counter = 0;
    for (int n = 0; n < files.Length; n++) {
        var file = files[n];
        var ext = file.Extension.ToLower();
        var lc_name = file.Name.Substring(0, file.Name.ToLower().IndexOf(ext));
        if (lc_name.IndexOf("_s") == -1) {
            var thumb = String.Format("{0}_s{1}.ashx?w=240&h=240", lc_name, ext);
            if (td_counter == 0) {
                sb.Append("<tr>");
            }
            sb.Append(String.Format("<td><a href=\"{0}\" target=\"_blank\"><img src=\"{1}\"></a></td>", file.Name, thumb));
            td_counter++;
            if (td_counter == 3) {
                td_counter = 0;
                sb.AppendLine("</tr>");
            }
        }
    }
    sb.AppendLine("</table>");
    divDefault.InnerHtml = sb.ToString();
}

Each of the DSC*.JPG images is between 6-8 MB.

The page would load, but all of the images were not available.

I saw ImageResizer entries in the Web.config file, so decided the packages needed to be run on this PC.

I entered Package Manager Console to to get the latest:

PM> Install-Package ImageResizer.MvcWebConfig
PM> Install-Package ImageResizer.Plugins.DiskCache
PM> Install-Package ImageResizer.Plugins.PrettyGifs

I still did not see the images, so I debugged and found that I needed to look into the resizer.debug.ashx file.

The first error I saw staring at me there was:

Plugins(ConfigurationError): An instance of the specified plugin (ImageResizer.Plugins.Basic.MvcRoutingShimPlugin) has already been added. Implement IMultiInstancePlugin if the plugin supports multiple instances.

The full resizer.debug.ashx file is on Paste Bin: http://pastebin.com/iVT6QJS5

How do I remove these duplicates? Do I need to tell Nuget to uninstall first? Do I need to reboot or restart VS between Nuget remove and Nuget install?


Solution

  • Remove <add name="MvcRoutingShim" />, as it's loaded by default already - your configuration is trying to load another instance.

    It doesn't look like the Install-Package for DiskCache and PrettyGifs worked, though, as those .dlls cannot be found