Saturday, August 22, 2009

Licensing ActiveReports 6

Licensing with ActiveReports has been one of the biggest pain in the butt"est" topic that I have ever seen. Even though in concept, licensing is a very simple thing to accomplish, people continue to run into issues. One of the most common complaints has been "Everything works fine on my development machine, but when I deploy the application to production server I get the red evaluation banner in report documents". This drives people nuts and immediate assumption is made that ActiveReports is at fault. If a little bit time is spent in understanding how licensing works, it will make people's life lot easier. In general following ActiveReports Licensing documentation should be enough to resolve most of these issues.

ActiveReports uses standard .Net methodologies of licensing a component. There are no intentions to re-invent the wheel. It is there and it runs fine.

To start with, you get into licensing if you like a product. I would recommend that you install ActiveReports 6, mess with it and then decide. Email if you have any questions and GrapeCity support team will help you out. You can also post on the ActiveReports 6 forum if you want. Support is free. If you do decide to buy the product, and after all the etcs. and etc., you will have a serial number issued to you by GrapeCity. You are now ready to license ActiveReports 6. If you already have a build installed, run the installer again and select "License ActiveReports 6" option. You enter your name, email and serial number that you would have already received from GrapeCity, hit "Next" and you are good to go.

In order to create a license.licx file in Visual Studio, create a new WinForm project, add ActiveReports 6 template from "Add New Item". If the machine is licensed, a license.licx file is created in the project. If you open the file in TextPad, you will see one line, containing information about type, Assembly, Version, PublicKeyToken (in that order). Here is an example:

DataDynamics.ActiveReports.ActiveReport, ActiveReports6, Version=6.0.1000.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff

You need to make sure that version information for the ActiveReports6 dll is correct in case you upgraded to a hotfix or service pack. There might be other listings in the same file if you are using other licensed components in your project. Make sure the "Build Action" on license.licx is set to "Embedded Resource". Select the license.licx file in solution explorer and see the properties. First property listed is "Build Action"

You design your reports, run them and the red evaluation banner is gone from the bottom of each page that is generated in report's document.

Now is the time to deploy. By that I mean that you will either send the executable to your client or to whoever you want to. Important point here is that it will NOT be run on your machine. Your client's machine does not has ActiveReports 6 installed. All they want to see is the reports WITHOUT the red evaluation at the bottom of each page.

To make sure license is embedded in the executable, "Rebuild" (Alt+Shift+B+R") the solution. If you don't have reflector, download it. Open the executable in reflector, expand the node for your application and you will see a file named MyApp.exe.licenses ("MyApp" being the project name) embedded under "Resources". If you double click on it in the reflector, you can also see some textual information on what is in there.
If you don't see the .licenses under "Resources", something got messed up and you need to re-build the solution.

If license.licx doesn't exist or did not get generated for some reason, you can add it manually. Create a file named license.licx in TextPad/NotePad/etcs, add the component information as I mentioned above(one per line) and include it in the project. It can go in the root folder or in the 'My Project" folder for the project. Again, make sure the "Build Action" is set to "Embedded Resource"

That is up the exe and the dependent dlls and you are good to go. WinForms are simple and the above holds true for Web Application projects too.

And then..there are WebSites.

ActiveReports file by default goes inside the App_Code folder, when added through "Add New Item" since it is an external class/type. You can choose to put it anywhere you want to, but the "View Designer" option will not be available. License.licx will get generated if the report opens in design view. So, right click on report file in the solution explorer, select 'View Designer". You will notice that license.licx gets generated in root folder. Context menu on license.licx(right click on this file) will now have a "Build Runtime Licenses" option. Also, if license.licx file is selected in Solution Explorer, Build menu will have an option for "Build Runtime Licenses"

For website project, license.licx has to be in the root of website.

Lesson learnt from above is that report has to open in design view in IDE for license.licx to get auto-generated. In winform/web application projects, it happens by default when you add the report from "Add New Item". In website projects, once the report gets added to App_Code folder, you will have to right click on the report and click on "View Designer". Once the report opens in desing view, license.licx gets generated.

Since I have professional edition of ActiveReports 6 installed on my machine, I dragged WebViewer control that comes with ActiveReports 6 on to an aspx page from the toolbox and license.licx was generated. At the same time, App_Licenses.dll is also created in the bin folder. When you deploy websites, App_Licenses.dll also needs deployed on the production machine. it has to be in the bin directory in the root of the website. Now, for some reason, if you happen to delete this App_Licenses.dll, you can regenerate it by right clicking on the licx file and selecting "Build Runtime Licenses" option. It will re-create the App_Licenses.dll in the bin folder.

I have read somewhere that VS2008 initial release will screw this up(App_Licenses.dll gets corrupted somehow), so I guess you should move on to SP1.

Another scenario involves creating licensed application when no visual studio is involved. I would suggest getting familiar with lc.exe and the various flags that you can use to create .licenses file that can be embedded as a resource in an executable. I personally prefer command line, but majority of the users hate it, so I will stay away from it too. I couldn't find how to generate App_Licenses.dll for website projects using lc.exe. Is it possible?

References: Robert Dupuy has done a great job with these 2 articles. Part 1 and Part 2