I was trying to get SubSonic to run on a Free Hosting Environment (on GoDaddy) but unfortunately I kept getting a SecurityException when the code would attempt to save an entity. The code looked like this:
faq.Save(); // Saves a faq item to the database.
This code would save the new FAQ entity to the database. Unfortunately this code would throw an exception. The reason the code threw an exception is because in SubSonic, the Utility.cs file trys to write to the Trace listeners. The Trace listeners have a SecurityAction that demands a security permission. On GoDaddy, they lock down this access. Why? Who knows. They’re hosters, they do what they do. GoDaddy usually has everything locked down to a medium trust environment.
The documentation states that you can turn off the trace by setting a flag called “enableTrace” to false, BUT… because this doesn’t work because the SecurityAction Demand walks the call stack right when its referenced in code at runtime. Since the flag is being checked in the calling code, the security action is being checked in the stack when the class is called.
This has been addressed in the SubSonic forums and it looks like it will be fixed soon. Here’s how to get around it for now.
Open the source for the SubSonic project. Go into the AbstractRecord.cs and comment out any line that has the following call:
Utility.WriteTrace("...");
From my finds, those line numbers are:
- 901
- 948
- 951
- 957
- 962
- 995
- 1002
Comment all of those lines out, and then recompile the SubSonic project.
Then in your project, delete your SubSonic.dll reference, and now reference the new SubSonic.dll that you just built. This DLL will not have the call that writes to the trace.
This will avoid the Security call that eventually throws the exception.
The .Save() call will now succeed.
Good luck. ๐
Jr says
any chance you would want to share the compiled source so that users could then just easily upload it to their shared hosting accounts for deployment?
Donn Felker says
This post I so old that the source would not be the same that is available
from the current subsonic project. It would be best to take the current
source and update it. Unfortunately I don’t have time to do that. Please let
me know if you do and ill update this post with a link.