I am attempting to run my ASP.Net application with Medium Trust as my hosting provider has set their web environment to medium trust.
I have read all the past threads on this issue and none have helped me fix this problem.
After extensive research, I believe this has something to do with LLBLGenDatasource.
I am attaching a complete demo solution containing an asp.net website, llblgen project, a .sql file to install the database (sql2k5), and the llblgen generated code.
From the attached test solution, it is easy to reproduce the issue. If you change the trust to "Full", the application works, but when changed to "Medium", it throws the exception below.
<trust level="Medium"/>
The exception I am getting is:
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.GetObjectData(SerializationInfo info, StreamingContext context) +0
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +7629722
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +51
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +410
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +134
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) +13
System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +842
LLBLGen version 2.6 Final
SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll version=2.6.0.0; File version: 2.6.09.0313
SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll version=2.6.0.0; File version: 2.6.08.1114
Database used: SQL Server 2005
Template: SelfServicing
PS: On an unrelated topic, I had great difficulty in zipping this solution and to get it under the upload size limit that you guys have set. Considering that the code generated by LLBLGen for a handful of tables in my case is about 4 MB, I am not sure how to get the the zip file to be under 500k. I request you to raise this limit as this will help users send you viable test cases.
I had to use a program called 7-zip to zip the file as normal zip would have created a file bigger than the limit. Also, I had to remove the LLBLGen runtime dlls to reduce the size of the zip file.