code access security system does help to prevent overly trusted applications and premission denied to your application. So, mostly this error came When you moved your application from localhost to network server. Below link will helps you to solve this issue
Link :http://blogs.msdn.com/b/shawnfa/archive/2003/06/20/57023.aspx
Note: If you have alternative solution, please comment below to share with us.