This project is read-only.

Media gallery error when MediaFolder module installed

Sep 23, 2011 at 1:26 PM

When media gallery is installed together with Media Folder module, I get the following error and my site is foobar.

I would really appreciate some advice on how to fix this..Our project deadline is already gone.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 46:             _thumbnailService = thumbnailService;
Line 47: 
Line 48:             if (!_mediaService.GetMediaFolders(string.Empty).Any(o => o.Name == ImageGalleriesMediaFolder)) {
Line 49:                 _mediaService.CreateFolder(string.Empty, ImageGalleriesMediaFolder);
Line 50:             }

Source File: c:\Users\thanos.panousis.INDICE\Desktop\Orchard.Source.1.2.41\src\Orchard.Web\Modules\Mello.ImageGallery\Services\ImageGalleryService.cs Line: 48

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Contrib.MediaFolder.Services.RemoteStorageProvider.InitializePaths() +91
   Contrib.MediaFolder.Services.RemoteStorageProvider.get__storagePath() +90
   Contrib.MediaFolder.Services.RemoteStorageProvider.MapStorage(String path) +119
   Contrib.MediaFolder.Services.RemoteStorageProvider.ListFolders(String path) +154
   Orchard.Media.Services.MediaService.GetMediaFolders(String relativePath) +70
   Mello.ImageGallery.Services.ImageGalleryService..ctor(IMediaService mediaService, IRepository`1 repository, IRepository`1 imageRepository, IThumbnailService thumbnailService, IRepository`1 imageGalleryPartRepository, IOrchardServices services, IStorageProvider storageProvider) in c:\Users\thanos.panousis.INDICE\Desktop\Orchard.Source.1.2.41\src\Orchard.Web\Modules\Mello.ImageGallery\Services\ImageGalleryService.cs:48

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct& signature, RuntimeType declaringType) +0
   System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct signature, RuntimeType declaringType) +15
   System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +281
   System.Reflection.ConstructorInfo.Invoke(Object[] parameters) +17
   Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +

Sep 23, 2011 at 3:23 PM


Please try creating a folder called "ImageGalleries" inside your media folder and let me know the results.


Gabriel Mello

Sep 23, 2011 at 3:57 PM

thank you for the reply.

Just tried it. MediaFolder installed and configured with a directory that contains "ImageGalleries". ImageGallery is wiped from the db and the filesystem, I install it again from the gallery and get the same exception.

I have verified that in RemoteStorageProvider.cs:line 52 

   private void InitializePaths() {            
	var configuration = _orchardServices.WorkContext.CurrentSite.As<RemoteStorageSettingsPart>().Record;

WorkContext is null.


Sep 23, 2011 at 5:50 PM

This error seems to be an Media Folder issue. I took a look at and the review is not pretty.

The latest release is May 4 and Orchard 1.2 was released in June. Maybe it's just not compatible with Orchard 1.2.

I'll try to reproduce your error when I get home. Until then, try getting in touch with Sébastien Ros. He is a very capable developer, he may help you with this issue.

Sep 23, 2011 at 5:56 PM

Hello there and thank you for your replies.


The thing is that the media folder module works just fine right until you install image gallery. I'm not sure who's fault is this, the thing is that I need both.


I have also posted in their forum..

Sep 23, 2011 at 8:14 PM

I installed MediaFolder module with image gallery and just got an stack overflow (infinite loop) just like commented by a user in


Sep 26, 2011 at 9:24 AM

Hello Gabriel,

I am not getting a stackoverflow but rather the error in the top of the discussion.

Could you help me debug this? I am not sure who's "fault" this is, imagegallery's or mediafolder's, but it seems that only image gallery has the specific issue. How can I debug this further?


Sep 26, 2011 at 1:15 PM


Inside the Modules/Mello.ImageGallery folder there is a "normal" csproj that you can open with Visual Studio and debug as usual. You can either add this csproj to the Orchard solution or you can debug on IIS directly attaching the dubugger.

If your trying to attach the debugger and do not see the symbols loaded, i.e. can make the breakpoint work, do this:

  • Open the csproj and compile it to Debug
  • Copy the Mello.ImageGallery.dll and Mello.ImageGallery.pdb from Mello.ImageGallery bin folder to the Orchard bin folder.