Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

VirtualPathUnifiedProvider is null



I have a fresh install of EPi 6 with Composer and in my code I am doing the following:

vpp = System.Web.Hosting.HostingEnvironment.VirtualPathProvider as VirtualPathUnifiedProvider;

if (vpp != null)


// do some stuff


However vpp is always null, is there a basic setting etc that I am blindly missing :-)

Thanks a in advance

Aug 04, 2010 18:30

I might be mistaken, but it seems like you're just casting a class to another class, which make no sense. You're missing the actual vpp object. What are you trying to achieve?

Aug 05, 2010 9:43

How did you solve this?

Feb 27, 2013 13:51

VirtualPathProviders are "chained" together (they have a property Previous that points to next in chain). System.Web.Hosting.HostingEnvironment.VirtualPathProvider will just point to the last in chain which might or might not be a VirtualPathUnifiedProvider (depending on which is registered last in your configuration).

If you are looking for getting a handle to a specific VirtualPathUnifiedProvider my suggestion is to use EPiServer.Web.Hosting.VirtualPathHandler.Instance.VirtualPathProviders where you can find the provider you are looking for.

Feb 27, 2013 14:11

Hello Johan, thank you for your fast answer, for my case, it is a VirtualPathNativeProvider, still it is null, even UnifiedFile casts are null. How am i suppose to do? customFile is null in this example.

 ICollection<VirtualPathProvider> vpppp = EPiServer.Web.Hosting.VirtualPathHandler.Instance.VirtualPathProviders.Keys;

                    UnifiedFile customFile = null;
                    foreach (var x in vpppp)
                        VirtualPathNativeProvider x2 = x as VirtualPathNativeProvider;
                        if (x2!=null && x2.ProviderName == "ImageBank")
                            VirtualFile vf = x2.GetFile(path);
                            customFile = vf as UnifiedFile;

    VirtualPathNativeProvider vpp = System.Web.Hosting.HostingEnvironment.VirtualPathProvider as VirtualPathNativeProvider


Feb 27, 2013 15:05

To get a file you should not need to call to a specific provider, since they are chained you should call the first and that one will send it to next in chain until a provider hanldes the file or null if no provider handles the file.

So if you call:

var file = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(path)

what do you get back? Typically if no provider matches you get an instance of MapPathBasedVirtualFile.

What does your path look like? It should be a relative path like for example /Global/MyFile.jpg or ~/Global/MyFile.jpg

Feb 27, 2013 15:13

oh, i get it, but i do get a VirtualFile, but when i cast it to UnifiedFile it is null. Any Ide?

Strange behavior, the code below works though:

  UnifiedDirectory directory = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(originalsPath) as UnifiedDirectory;


Feb 27, 2013 21:24
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.