Hi @Cacenco, Michael ,
Thanks for posting the stack trace. I think this is an assembly version mismatch rather than an IIS configuration problem.
System.Web.WebPages.Administration.dll in your bin folder is likely a different version than the System.Web.WebPages.dll it calls into, so the .NET security transparency model blocks the call during pre-application start. This usually shows up after an MVC or Web Pages upgrade where the DLLs and the binding redirects in web.config fell out of sync.
A few things to try:
- Check the section of your
web.configand make sure the redirects forSystem.Web.Mvc,System.Web.WebPages,System.Web.WebPages.Razor, andWebMatrix.*point to the versions actually deployed in bin. - In Visual Studio, run Update-Package from the Package Manager Console so all the Web Pages assemblies land on the same version, then republish.
- If you are not using the Web Pages site administration feature, try deleting System.Web.WebPages.Administration.dll from bin. It is not required at runtime and removing it has resolved this for others.
If none of that helps, could you share:
- The section from your
web.config - The file versions of
System.Web.WebPages.dll,System.Web.WebPages.Administration.dll, andSystem.Web.Mvc.dllin your bin folder - What changed right before this started, such as a framework upgrade, a new publish, or a server patch
That will help confirm whether it is the mismatch or something else. You may also find this https://learn.microsoft.com/aspnet/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2 useful if this followed an MVC upgrade.
Let me know how it goes. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback.
Thank you.