Free Support Forum -

How to use the viewer with Unity



I need to use your viewer in a project that uses Unity for DI.
After following the instructions provided here:
…I had problems in resolving the proper implementation of Groupdocs.Web.UI.IRootPathFinder when hitting the controller action document-viewer/GetScript”.
After configuring Unity to resolve this to Groupdocs.Web.UI.RootPathFinder, it crashes inside the controller with the following exception:

[NullReferenceException: Object reference not set to an instance of an object.]
   Groupdocs.Web.UI.Controllers.GroupdocsViewerController.() +112
   Groupdocs.Web.UI.Controllers.GroupdocsViewerController.GetScript(String name) +18
   lambda_method(Closure , ControllerBase , Object[] ) +104
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157

Since I can’t figure out why this happens, my first guess is that it has to do something with unity too.

But I have tried this :
	IUnityContainer container = new UnityContainer();
	DependencyResolver.SetResolver(new Unity.Mvc4.UnityDependencyResolver(container));
…and it didn’t work either (I got the same error).
How can I fix this?



When I modify my controller factory to handle the controller construction by code like that (notice that I don’t provide any parameter - if I do I get the same error):

if (controllerType.Name == “GroupdocsViewerController”)
return new GroupdocsViewerController();

…I do get the scripts from the controller and I see the viewer, but it fails to get the images and the fonts.
For them, I get a :

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Any help would be welcome.


Hi Petros,

Thanks for getting in touch!

Can you share a sample project that demonstrates the issue that you are describing and we’ll then be able to investigate this issue locally, and come back to you with a more detailed response once we reproduce this locally?

Please share on Dropbox if possible to avoid attaching large files to this thread,

Many thanks,


Derek Hyland, Venture Lead, GroupDocs (Aspose Ltd)
Office: +1 (214) 329 9760
Skype: derekh.aspose



I have the same issue using StructureMap IOC container.

I did the same workaround the the controller activator:

public class StructureMapControllerActivator : IControllerActivator
public StructureMapControllerActivator(IContainer container)
_container = container;

private IContainer _container;

public IController Create(RequestContext requestContext, Type controllerType)
if (controllerType.Name == “GroupdocsViewerController”)
return new GroupdocsViewerController();

return _container.GetInstance(controllerType) as IController;


i got it to render. But it does not see the license file, and saying “this viewer has been created using an unlicensed version of Groupdocs Viewer for .Net.

I think the problem is with the constructor for GroupdocsViewerController().
==> should i be using the GroupdocsViewerController(Groupdocs.Web.UI.IRootPathFinder rootPathFinder) instead??? is so what is the value for IRootPathFinder???

I used these lines, and it does see the storageRoothPath, becuase I see the temp folder created with the cache and processing folders for the rendered file.
Viewer.SetLicensePath((Server.MapPath(”~/GroupDocLicense/GroupDocs.Viewer.lic"))); Viewer.SetRootStoragePath(Server.MapPath("~/GroupDocsCache/"));
But the problem is it is not see the license file at all…
Please advise.


Hello again,

I have sent you a link to a demo project with a private message.

I do the constructor initialization hack in :

The problems that I see are:
1) With out the hack mentioned above, the viewer doesn’t work at all (I get a null object reference in your constructor).
2) With the hack in place, the images of the viewer are not loaded (the server responds a 404 code for them).

Best Regards,


If you have any problem getting my sample, let me know.

Also, if you manage to reproduce the problem with my sample, let me know so that I do not worry.



Hello Alex,

We are sorry to hear that you have such issue. To be able to help you with this issue we will need additional info about it:

1. Which version of the GroupDocs.Viewer you use?
2. Can you please share with us your license file that we can check the Viewer with it.
3. Full path for the Viewre license (where it placed and highlight root folder of the project in the full path.)

Thank you.


Hi Kostas,

Since the sample includes access to a MSSQL DB, that you didn’t share, it’s taking some time to mock out the DB functionality to reproduce the issue with that project, locally, our dev support team are currently investigating, most likely they will come back to you either tomorrow or Wednesday with feedback.

Many thanks,


Derek Hyland, Venture Lead, GroupDocs (Aspose Pty Ltd)
Office: +1 (214) 329 9760
Skype: derekh.aspose


OK. Great.

If I am not mistaken, the demo project used “code-first” approach, so probably if you type “Update-Database” in the “package manager console” it will automatically create a new database in the SQL Server instance that the connection string (in the config) points to.
You just need the appropriate login and user with access rights to create the DB.

Otherwise, here is the only table that you will need (if I don’t forget anything):

USE [MyDemoDb]

CREATE TABLE [dbo].[FileItems](
[ID] [uniqueidentifier] NOT NULL,
[FileName] nvarchar NULL,
[Type] nvarchar NULL,
[DateModified] [datetime] NOT NULL,
[Path] nvarchar NULL,


But if you create the DB using the above script you may need to remove some parts of the code that have to do with “code-first”.

I hope this helps,


Please, also note that we have just tried your annotations assembly and we have the same problem there too (you seem to be using StructureMap in there).

We haven’t found any workarounds for it yet.
After tryign to configure some of your interface implementations for the DI to resolve, we get the following error:

StructureMapException - StructureMap Exception Code: 202
No Default Instance defined for PluginFamily Groupdocs.Core.IUserService, Groupdocs.Web.Annotation, Version=, Culture=neutral, PublicKeyToken=c037f897af36d52e

Best Regards,


Hello Kostas,

We are sorry to hear that you have such issue.

I downloaded yours solution and worked with it for some time. First of all I had to replace all stuff that was not present in the project like the database and simultaneously make it functional. I figured out that files in your project are stored locally while their descriptions are located in the database. So I created own fake repository with several hardcoded file descriptions and corresponding documents ( which filenames are GUID the same as in the hardcoded instances of file descriptions). Then I switched from “real” repository to my own in the “ConfigureUnityContainer” method (container.RegisterType<IFileItemRepository, FakeFileItemRepository>). Finally, I modified “FilesController” a little.

After binding this project to the IIS Integrated Mode I started it successfully. With your hack in “GetControllerInstance” method GroupDocs.Viewer works perfect. The problem with toolbar icons that are missed (“With the hack in place, the images of the viewer are not loaded (the server responds a 404 code for them)”) should be solved very easy: you need to add a key-value pair runAllManagedModulesForAllRequests=“true” to the “configuration/system.webServer/modules” node within a web.config.

With your hack “if (controllerType.Name == “GroupdocsViewerController”) {return new GroupdocsViewerController();}” all works well, but I cannot make it work without it. For some reason Unity framework is not compatible with “GroupdocsViewerController” which is responsible for displaying a document, and I could not make it work properly, without yours hack.

All registrations of the GroupDocs.Viewer’s classes in the “ConfigureUnityContainer” method are useless, no matter is hack enabled or not, so you can remove them.

Hope it helps. About your second problem with Annotation - can you give as more info? You can also share the project in the same way as this.

If you will have more questions please feel free to contact us.


Thanks for looking into this and sorry for all the trouble with the database.
As in the previous project, we had to resolve the controller manually (in Configuration.UnityControllerFactory.GetControllerInstance() ):
if (controllerType.Name == “AnnotationController”)
return new AnnotationController();

Then, the viewer loads fine, but the document doesn’t.
When posting on the “document-viewer/ViewDocument” controller, I get a :
{“success”:false,“Reason”:“Failed to load file from the storage.”}
I have tried many different forms of path for the PDF file in FilePath() function of your viewer, but nothing seemed to help.
Note that I set this:
WidgetFactory.Initialize(this.Context, @"~/App_Data");
And my document is inside ~/App_Data the folder.
So, I don’t understand why it cannot find the file.


This message was posted using Email2Forum by denisgvardionov.



We have solved the major issues in the annotations viewer (even the issue that we emailed you for posted above), but now not all annotations seem to work.
E.g., I get a javascript error when using the polyline annotation tool:

  1. Uncaught TypeError: undefined is not a function GetScript?name=GroupdocsAnnotation.all.min.js:1
    1. a.extend.createPolylineAnnotationGetScript?name=GroupdocsAnnotation.all.min.js:1
    2. o._mouseCapture._mouseDistanceMet._mouseDelayMet._mouseMoveDelegateGetScript?name=libs/jquery-ui-1.10.3.min.js:5
    3. v.handle

It seems that it fails at this point in code:


As far as I see, no script request fails. So, I don’t know why this is not defined.
Also, it seems that your sample project for the MVC annotations has the exact same problem.

We have just found the solution by defining the following JS function :

String.prototype.format = function () {
var args = arguments;
args[’{’] = ‘{’;
args[’}’] = ‘}’;
return this.replace(
function (item) {
var result = args[item.substring(1, item.length - 1)];
return typeof result == ‘undefined’ ? ‘’ : result;

Best Regards,


Hi Kostas,

In general, GroupDocs.Annotation is more complicated product and it requires more configuration. I cannot guarantee that the reason of your issue is clear for me, but it seems that you didn’t specify a routing for annotations in the “RouteConfig.RegisterRoutes”: “routes.MapAnnotationRoutes();” (“MapAnnotationRoutes” is an extension method from “Groupdocs.Web.Annotation.Mvc” namespace).

I suggest you read the article “How to use GroupDocs.Annotation for .NET in an ASP.NET MVC 5 Project” (

(This problem was solved via Banckle Live Chat)


Hello Kostas and thanks for posting this report,

But must admit that this is strange, I have sample solution and cannot reproduce your error: polyline annotation tool works well without errors both in the MVC and in the WebForms sample projects.

Can you please specify what exact version of Groupdocs.Web.Annotation.dll are you using?



We use Groupdocs.Web.Annotation version
This is odd indeed.

We have downloaded it from here:
And used the MVC version.

Best Regards,


Thanks for quick reply,

That explains it. Groupdocs.Web.Annotation version is old and the error you described is a bug, which is fixed in the new versions. I’ll send you a link to the new preview version via email at yours email address

Since it is preview I want to ask you do not share the link and the library. It also has new features, differences and therefore dependencies, you need to add references to additional libraries. If you will have any issues or questions with it, you can post them here or at my email