Wednesday, March 28, 2007

NetSpell checker works in medium trust environment using AllowPartiallyTrustedCallersAttribute

Hi all,

just a quickie, I have been using this fantastic open source free spell checker and I am very happy with it as it is completely integrated to the FreeTextBox.

It is called NetSpell and in order to download it you must go to this site :
http://www.loresoft.com/Applications/NetSpell/default.aspx

The problem is when you try to make netspell work in a shared hosting environment that will be more secure than your dev webserver and will more than likely run in medium trust.

The only problem is that NetSpell does not by default allow the assembly to run in partial trust and therefore the only way to get it to work is to add :

[assembly: AllowPartiallyTrustedCallersAttribute()]

line to the AssemblyInfo.cs file of the NetSpell.SpellChecker project

Soooooo....

1. I downloaded the code locally to my C: drive,
The full source is available here using the mighty SVN source code manager :
http://sourceforge.net/projects/netspell/

2. Went to the ..\NetSpell\trunk\NetSpell\src\NetSpell.SpellChecker folder,
3. Edited the AssemblyInfo.cs file to include [assembly: AllowPartiallyTrustedCallersAttribute()]
4. Added a reference at the top of the file to using System.Security;
(required for the AllowPartiallyTrustedCallersAttribute element to work)
5. Recompiled the project
6. Copied the new NetSpell.SpellChecker.dll to my web project and...
7. BINGO! everything worked like a charm on my medium trust environment!!!

Hope those who struggled with this will manage to find my post and solve their problem!

Cheers,
Etienne

3 comments:

avshash said...

Etienne hi! many thanks for the clever post about the SpellCheck.
I'm quite a novice when it comes to programming. Although it looks like I achieved a lot so far without much knowledge.
I'd like to learn how to compile the source code for SpellCheck to get the DLL you made. Or would you be able to post a link to that DLL? (the one you made with the 'AllowPartiallyTrustedCallers..'? Thanks! Avishay

Etienne said...

Hi Avishay,

I order to compile the code you simply need to use Visual Studio Express (or Visual Web Developer) downloadable for free from the microsoft website.

Do a Google search and you will find it.

Cheers!

avshash said...

Thanks!
I am actually using VSExpress 2005 I just never checked how to compile a code and make a DLL out of it. I'll do my little research and thanks again for your quick reply :)
I hope London is treating you well, I used to leave there for many years and I miss it a lot.