Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Licensing and the GAC

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Licensing Support
View previous topic :: View next topic  
Author Message
alanseedhouse



Joined: 09 Jul 2007
Posts: 6

PostPosted: Mon Jul 09, 2007 10:45 am    Post subject: Licensing and the GAC Reply with quote

The problem I have is this:

1. By default, controls in the GAC are not displayed in the Add References dialog in VS2005. After much research I found that you have to add a key to HKLM/Software/Microsoft/.NETFramework/AssemblyFolders/<my control>. The (Default) value of the key should point to a standard windows folder containing the control (e.g. C:\Program Files...). So it appears that you have to have 2 copies of the control...One in the GAC and one in a normal windows folder. According to sources on the net this is how MS do it and I have checked a few .NET controls installed in my PC and this seems to be correct (unless anyone knows different Smile

2. At design-time the Infralution code checks for a license file in the same location as the control (the windows folder in this case...not the GAC). The license file is then found and embeded into the client assembly.So for so good!.

3. Then you complile the project (which references the licensed control). What happens here is at compile time the License context is Design-time but the Infralution code now looks for the license file in the GAC (found by using the ITypeResolutionService) As the license file is not there it does not get embeded into the application so you get license errors when you then attempt to run the project (and the Infralution code looks for an embeded license).

So the result is...The control appears to be licensed at design-time (because it can find the license file), but at run-time is appears to be unclicensed.

The whole GAC thing about using 2 copies of the control is very confusing. Am I missing the point here?? Please can anyone advise how to install a licensed control into the GAC, make it visible to the Add references dialog in VS2005 and ensure that the licensing system still works correctly.

I am thinking about modifying the Infralution code so that it looks for the license file in the AllUsers application area and does not look for the license file in assembly related folders. I don't want to do this unless I have to and I am hoping that it is just my misunderstanding of how the sytem works

Cheers...Alan S
Back to top
View user's profile Send private message
alanseedhouse



Joined: 09 Jul 2007
Posts: 6

PostPosted: Mon Jul 09, 2007 11:29 am    Post subject: More info on this Reply with quote

I have done some more research on this problem. If I do not add the sub key/value to the AssemblyFolders key and add the control to the toolbox by using the browse button I do not get the problem. If you look at the properties in the references the path shows the control as being in the GAC.

If you add the subkey to the AssembyFolders the control is listed in the Choose Items.. dialog. After adding it check the references properties. This will show the control as being in the windows folder (not the GAC).
At compile time VS2005 sees the control as being in the GAC so it cant find the license file.
Back to top
View user's profile Send private message
alanseedhouse



Joined: 09 Jul 2007
Posts: 6

PostPosted: Mon Jul 09, 2007 4:10 pm    Post subject: Now I understand! Reply with quote

OK, I think I understand what is happening! when you are using an entry in the AssemblyFolders key.

1. Because of the AssemblyFolders subkey the control is listed in the "Choose Toolbox Items' dialog....great!

2. You add the control to a form. The path in the references shows the control's windows folder (e.g. c:\program files...) (not the GAC).

3. Infralution prompts you for a license which you then enter.

4. Infralution saves the file in the control's windows folders (not the GAC)

5. You run the program which rebuilds the project but this time VS uses the copy of the control in the GAC rather than the windows folder therefore infralution prompts again for the license....not good! This time its saves the license in the control's GAC folder.

6. The project then runs with no more licensing errors.

So to summarize, If you want a control to appear in the "Choose Toolbox Items' dialog and add a subkey to the AssemblyFolders key you may have to enter the license twice. Once when the control is placed on a form and again when the client project is run (and built).

I have spent a whole day on this problem but I think I understand now. I am still not sure how to cure it other than not displaying the control in the 'Choose Toolbox Items' list or modifying the Infralution code to save the license file in the common application data or Isolated Storage.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Jul 09, 2007 11:26 pm    Post subject: Reply with quote

In .NET 1.1 when an assembly was placed in the GAC the path to the original assembly location was saved as the assembly CodeBase property. ILS was able to use the Codebase to save the license key against the original assembly (rather than in the GAC directory). In .NET 2.0 Microsoft changed this behaviour and GAC assemblies no longer report their original Codebase. This leads to the behaviour you have discovered below.

If you use the default location for license file for assemblies registered in the GAC then the customer will have to enter the license key twice - once when using the control at design time and again when they do a build. This is not too bad - however the real problem is that installing a new version of your software will cause the GAC folder where the license is stored to be destroyed and recreated meaning that the customer will have to re-enter their license each time they install a new version.

The solution is to save the license file in the common application data directory. To do this you derive a new LicenseProvider class from EncryptedLicense provider and override the following:

Code:
       protected override string GetLicenseDirectory(LicenseContext context, Type type)
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
            path += @"\MyProduct";
            return path;
        }

        protected override string GetLicenseFilePath(LicenseContext context, Type type)
        {
            string directory = GetLicenseDirectory(context, type);         
            return directory + "\\MyControl.lic";
        }


Make sure that you change any LicenseProvider attributes and other code to use the new derived class. This assumes you are using the latest version of ILS code in which creates the license directory if it doesn't already exist (in the InstallLicense method).
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
alanseedhouse



Joined: 09 Jul 2007
Posts: 6

PostPosted: Tue Jul 10, 2007 7:17 am    Post subject: Thanks Reply with quote

Thanks a lot for quickly confirming what I found. What made it more difficult to understand is the VS caches a lot of stuff and you constantly have to close it down and re-open it (really annoying!!!!) so the results were not always consistent duting testing. It can take quite a time before the true behavior becomes clear.

I have now derived a new LicenseProviderClass from the EncryptedLicenseProvider class and overridden the GetLicenseFilePath() method to return a folder for my assembly in the common application data folder. I also had to override the GetLicenseProvider() method of the LicenseInstallForm to return an instance of my derived class otherwise the overridden methods do not get called when you enter the license key.

Placing the license file in the common application data folder would also allow more control over when a new license is required. The license file could be placed in a folder accessible by all versions of the control or you could create a sub folder for each specific version of the control. I also considered using Isolated Storage for this purpose as a control can always write to it irresepective of the file system security (or so I understand) but I think the common application data solution is the simplest.

Once again, thanks for your quick response. I think you have a great product and I am looking forward to purchasing the ASP payment solution soon.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Licensing Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group