After finishing one of the websites that were developed using Entity framework , I published it to hosting company server.When i tried to open the newly published site, i got the following error:
Parser Error Message: Type 'System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider' cannot be instantiated under a partially trusted security policy (AllowPartiallyTrustedCallersAttribute is not present on the target assembly).
After some investigation , I found that the mentioned error was caused by the following build Provider section that were placed in web.config by VS 2008:
<add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"/>
The “EntityDesignerBuildProvider” class is contained in System.Data.Entity.Design.dll which does not have the AllowPartiallyTrustedCallersAttribute and so any call to it in the partial trust will fail.
when i removed the mentioned “buildProviders” section and refreshed the site, i got the following error:
The specified default EntityContainer name 'entity model name here' could not be found in the mapping and metadata information.
Parameter name: defaultContainerName.
After that i started to think that removing the mentioned section prevented the complier from compiling the entity model.
I think the problem is that since i didn’t precompiled the website and just copied it to the hosting server(using “copy website” option), the runtime will try to compile it dynamically (including the entity model “edmx" file) hence the first mentioned error will occur.
many solutions comes to my head, like pre-compiling the website to avoid dynamic compilations on the hosting server, or just moving the entity model from App_code to a separate class library project which allow me to only build the class library project and publish the dll to the website Bin directory.
precompiling the website wasn’t an option for me because i know that i still need to apply partial updates to it and so i can’t re-upload the whole stuff every time i change something in the website.
So i selected the second solution.I goes a head and moved the entity model file “edmx” from the website App_Code to a separate class library project.then compiled entity model project and added it’s resulted dll to the website Bin directory.
Problem solved :)
Hope that help you !