I have two projects in my solution, project1 and project2.
Project2 tends to self host with Owin.
I have enable CORS using Microsoft.Owin.Cors package.
Both project have Microsoft.OWIN 3.0.1 and Microsoft.AspNet.Cors
5.2.3.
Then, I copy my project2.exe to project1's debug folder and call
prorject2.exe from project1.
Then, then the exception box rises when trying to call project2.exe.
The message is that it requires System.Web.Cors version 5.0.0.0
assembly.
When I downgrade the Microsoft.AspNet.Cors to 5.0.0.0, it
again says it requires Microsoft.Owin version 2.0.2.
Why does this occur and how do I fix this version conflict? Both the projects is built under .Net Framewrok 4.5.2.
In order to resolve to conflict you must tell your code which version of OWIN to use. this can be done from your application's app.config.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I got this error "Could not load file or assembly 'System.Web.Http, Version=5.2.3.0" why trying to publish the website (+webapi) to azure. It is working properly on my machine.
web.config:
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
the version of bin\system.web.http.dll is 5.2.30128.0. Got no luck when modifying new version from 5.2.3.0 to 5.2.30128.0.
You need to modify the web.config file to add assembly redirects:
....
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
...
</configuration>
It worked for me.
After upgrading to Azure 2.6 (from 2.5) and publishing web into Azure Web Apps, the web fails to start with exception below. It seems Azure 2.6 is not yet available at Web Apps. Anyone experiences this?
Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Try add the reference manually from the SDK directory and create a binding redirects.
C:\Program Files\Microsoft SDKs\Azure.NET SDK\v2.6\ref\Microsoft.WindowsAzure.ServiceRuntime.dll
<dependentAssembly>
<assemblyIdentity name="WindowsAzureTelemetryEvents" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WindowsAzureEventSource" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="msshrtmi" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.ServiceRuntime" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
</dependentAssembly>
We have recently upgraded our MVC3 application to MVC5 (rather, we are attempting to do so now).
The application runs successfully on some machines, but not mine. It also won't run on the web server.
I have compared the versions of the System.Web.* dlls with those on the working machine and they appear to be the same.
I have also followed the fixes from the other threads I found, with to no avail. I will have to search again to find those that I tried, but here is the first one that I remember.
Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'
What else would I need to change/update to prevent this problem?
Here is the error and stack trace:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:
System.MethodAccessException: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' 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:
[MethodAccessException: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed.]
System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule() +96
System.Web.WebPages.Administration.PreApplicationStartCode.Start() +41
[InvalidOperationException: The pre-application start initialization method Start on type System.Web.WebPages.Administration.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +547
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521
[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.WebPages.Administration.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9931916
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
UPDATE
Here is some info from my web.config
<compilation debug="true" targetFramework="4.5.2">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
...
</assemblies>
</compilation>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Xml" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Windows.Forms" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Drawing" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Services" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Abstractions" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Routing" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Deployment" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
For me this happened when i went to VS 2015. It seems that the system.web.webpages.administration.dll was remaining in the bin folder and this caused a problem. this happened when I upgraded some NUGet packages. I am unsure to which one. I deleted the .dll and this fixed the issue for me. I noticed when i reinstalled the web helpers it seemed to come back, so maybe that is the offending package?
Edit: I wanted to add that I did not find the dependency in the vbproj file in my case. I could find nowhere that my project used this .dll but all the same it seems to load up.
Just incase if anyone faced this issue when publishing the app to Azure app service
Go to settings in the publishing profile
check the checkbox "Remove additional files at destination"
Try this:
comment below two lines in site.csproj file
<!--<None Iclude="_bin_deployableAssemblies\System.Web.WebPages.Administration.dll" />-->
<Content Include="App_Data\XmlDocument.xml" />
for me, I solved it by removing the reference for System.Web.Administration.dll in the project. This site, pointed me to the right direction https://codedump.io/share/d2rw80bGmlwc/1/methodaccessexception-inside-systemwebwebpages-migrating-mvc-3-to-mvc-5
I also ran into this issue. Even after removing the System.Web.Administration.dll from the website\bin directory, I was then getting a permissions error on those DLLs.
I closed visual studio, and re-opened in Administrator mode (I must have missed this when opening the solution), loaded up the same solution, and then was able to rebuild successfully.
I had the same issue and after searching all over the place and trying different options which did not work, I simply deleted all the files from bin\ and published the site again and it worked. Many people pointed to certain .dll files but the easiest solution was what I did and the site is back up and running.
error-pic
Not a precise solution to this - but in case it's helpful - had similar error:
Attempt by security transparent method 'System.Web.WebPages.WebPageRoute.<.cctor>b__0()' to access security critical method 'System.Web.WebPages.Deployment.WebPagesDeployment.IsExplicitlyDisabled(System.String)' failed.
The cause was around the following binaries:
\bin\System.Web.Razor.dll
\bin\System.Web.WebPages.dll
\bin\System.Web.WebPages.Razor.dll
I found a version of the same asp.net site that was working (for example a QA/STAGE site - or another dev machine where this works).
Copied the binaries from here - this cleared the error.
Again - not a solution - but it might help you find the cause. Check your project references.
I am playing around with ASP.NET MVC5 and RavenDB. I wanted to use Raven's asynchronous API but for the life of me can't get it to work.
My controller (the actual query result is faked since there is no data in the DB)
public class BooksController : Controller
{
public async Task<ActionResult> IndexAsync()
{
var books = this.documentSession.Query<Book>();
Book book = await books.FirstOrDefaultAsync() ??
new Book { Title = "Programming WCF service", ASIN = "B0043D2DUK" };
return this.View(book);
}
}
And the view IndexAsync.cshtml
#using Hydra.FubuConventions
#model Hydra.Models.Book
#{
ViewBag.Title = "Books Asynchronous";
}
<h2>Books Asynchronous</h2>
#Html.FormBlock(x => x.Title)
#Html.FormBlock(x => x.ASIN)
The Web.config
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<customErrors mode="On" defaultRedirect="Error.html"/>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
It works perfectly fine when I use a synchronous controller method to feed it with a model. But with the asynchronous method it only displays
System.Threading.Tasks.Task1[System.Web.Mvc.ActionResult]`
I found plenty of posts here on stackoverflow that indicate that an older version of MVC might be the problem. But I checked the version of the MVC dlls (System.Web.Helpers v3.0.11001.0, System.Web.Mvc v5.0.11001.0 and System.Web.WebPages v3.0.11001.0) in my output folder which seem to be correct.
Any ideas what I am missing?
UPDATE
I compared the list of loaded assemblies. Other than the obvious differences by assemblies loaded in only one of the projects they were a match. The web.config is identical. I replaced the call to RavenDB with the same test stub that I used in the new project. Still get the type name rather than the view.
If you use a custom ControllerActionInvoker, you'll have to inherit it from AsyncControllerActionInvoker.
You must target .NET 4.5 and set httpRuntime.targetFramework to 4.5 in your web.config.
Your web.config lacks the assembly redirection directives found on a new MVC project. I suspect older MVC assemblies are installed in the GAC and are picked up by your app.
In any case, the behavior is a typical version mismatch. You need to find why the older assemblies are loaded by comparing the differences between your project and a new, clean MVC 5 project.
On a new MVC 5.2 project, the <runtime> section in web config contains these assembly redirections:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
You should copy the redirections from the clean project to your old project and see whether this solves the problem