API
Version 7.x > API > Assembly version error when adding custom DLL View modes: 
User avatar
Member
Member
christian.nickel-nist - 1/7/2014 11:07:42 AM
   
Assembly version error when adding custom DLL
Hello,

I've created a support DLL for my Kentico v7 web project to move some custom code out of app_code. The DLL compiles just fine but the website chokes after I've added the DLL to the /bin folder. I've added references from the /bin folder of the website (NOT the program installation folder) and is throwing an assembly error specifically for CMS.SettingsProvider and CMS.Controls:

CS1705: Assembly 'CMS.Controls, Version=7.0.5025.15764, Culture=neutral, PublicKeyToken=834b12a258f213f9' uses 'CMS.SettingsProvider, Version=7.0.5025.15745, Culture=neutral, PublicKeyToken=834b12a258f213f9' which has a higher version than referenced assembly 'CMS.SettingsProvider, Version=7.0.4947.22652, Culture=neutral, PublicKeyToken=834b12a258f213f9'

Three questions:
Is there any easy way to fix this?
Are these assemblies in the GAC, and is the /bin folder of the website the wrong place to use them from?
I am using hotfix 56, is this possibly hotfix related and should I upgrade?

Thanks,
Christian

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/7/2014 12:36:19 PM
   
RE:Assembly version error when adding custom DLL
The standard way to do this would be to have one solution file and add both those projects (Kentico website and other class project) to your solution. Then add a reference to that other class project in your Kentico website and it will automatically build that class project and copy the dll to your Kentico site.

If you support DLL requires Kentico DLL's then you need to have those referenced in your support DLL so it can build them and distribute them in your support DLL as needed. Sounds like you might be donig too much of once thing and not of another. To make things simple, you should keep your support DLL generic and simply pass objects, properties, values back and fourth. OR simply leave your custom code in your website (I'd recommend this option).

I have a few ways about this:

1) for client custom code, I use the best practice from Kentico and add a directory in the /App_Code directory with the same name as the site code name (in CMS SiteManager>Sites>Code name).

2) for my custom code that I use in many of my projects I create a directory called /App_Code/KehrenDev/ and add any classes I have there that may not be specific to the client or site but simply generic functions or methods that I find helpful and Kentico doesn't offer. By Default, this directory will not be part of any export if a client exports their site.

Best of luck
Brenden

User avatar
Member
Member
christian.nickel-nist - 1/7/2014 12:54:13 PM
   
RE:Assembly version error when adding custom DLL
Hi Brenden,

The setup of my solution and projects is exactly as you've described. A single solution with the Kentico website project and the class library added. The Kentico website has a project reference to my class library and automatically copies the DLL once built. I have done this many times before with other website and other CMS tools.

I used to have this same exact code in /App_Code/<SiteCodeName>/ and it became unmanageable in Visual Studio 2012 because of how it uses classes in that directory (waiting up to 10-30 seconds for VS to be respond after creating new classes or saving existing ones). It is also easier to unit test classes in a completely separate DLL, in my opinion.

The DLL builds just fine, but once I try to run the website I get the assembly version error that I've stated above. I simply want to fix this error so that my external class library can work with Kentico, any idea why I am getting assembly version errors?

Thanks,
Christian

User avatar
Member
Member
christian.nickel-nist - 1/7/2014 1:27:54 PM
   
RE:Assembly version error when adding custom DLL
Figured this out, though I still am unsure if things are all good...

I thought maybe this was related to the application of hotfixes to the Kentico installation and it seems to be. Essentially I downloaded hotfix 56 and extracted it separately and changed my library to reference the DLLs in the hotfix directory instead of the web project's /bin directory. This worked just fine and my site loaded without any issues.

The mystery to me is why the website worked with the existing DLLs in the /bin directory, are all the DLLs from hotfixes in the GAC?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 1/8/2014 12:46:10 AM
   
RE:Assembly version error when adding custom DLL
Hello,

If you are using custom assembly, after applying the hotfix you need to rebuild the solution. The new DLLs from the hotfix, copied to the BIN folder, have no idea about your custom DLL, so you need to rebuild the project, so the reference to your cusotm DLL is added to the new Kentico DLLs as well.

Best regards,
Juraj Ondrus