views:

197

answers:

2

Hi everybody... I'm developing a asp.net mvc application with nhibernate and I would not like to expose my objects mappings with NHibernate, so I created DTO for each entity and I'm trying to convert my Domain objects to DTO and send it to View. So I have in my sollution:

  1. ClassLibrary with my Domain (for NHibernate) and DTO objetcs
  2. Class library to make a SessionFactory adn Factories in my Project
  3. Asp.Net MVC 2 Application

So, I download AutoMapper to transform Domain objects in DTO and add a the code to do this in Application_Start of global.asax.

When I run in VisualStudio (by pressing F5) it works fine and my dtos are into the view, So when I publish this in IIS, I get a security exception =( in first line of conversion:

Mapper.CreateMap(); <--- this line throw exception Mapper.CreateMap();

System.Security.SecurityException: Failed request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

What can I do to resolve this to work in IIS ? When I will publish it on web server, the error will get too :(

Thanks

Cheers

+2  A: 

you need to run your IIS in full trust in order to have reflection permission, look here reflection permission

or here set trust level

you need this because Automapper uses reflection to emit code o_O
Omu
btw, check my http://valueinjecter.codeplex.com/, it's almost like Automapper but much better ;)
Omu
+5  A: 

Right click on the AutoMapper.dll > select properties > Unblock.

Then restart IIS

Lee Smith
Thanks man, i'll try it too!
Felipe
I was already running in full trust and was baffled until I realized that my AutoMapper.dll was "blocked". Good catch.
daveidmx
I had to remove the reference from my project and add it back again after unblocking in order to get this to work.
Samuel Jack