Entry point was not found exception

I have converted a project from MVC3+.NET4 to MVC4+.NET4.5 and I receive the exception Entry point was not found when invoking a controller’s action. My solution was to insert an assembly binding redirect inside web.config to point at MVC 4 assemblies: <runtime> <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″> <dependentAssembly> <assemblyIdentity name=”System.Web.Helpers” publicKeyToken=”31bf3856ad364e35″ /> <bindingRedirect oldVersion=”1.0.0.0-2.0.0.0″ newVersion=”2.0.0.0″ /> </dependentAssembly> <dependentAssembly> … Read more

Register global filters in ASP.Net MVC 4 and Autofac

There’s a new way of registering MVC global filters in AutoFac. First, remove the filter registration from your RegisterGlobalFilters because we will have Autofac handle adding them to our controllers/actions instead of MVC. Then, register your container as follows: var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterType<MyProperty>().As<IProperty>(); builder.Register(c => new CustomFilterAttribute(c.Resolve<IProperty>())) .AsActionFilterFor<Controller>().InstancePerHttpRequest(); builder.RegisterFilterProvider(); IContainer container = … Read more

ASP.NET MVC 4 Mobile Features

ASP.Net (actually the HttpBrowserCapabilitiesBase class) doesn’t recognize the Opera Mobile Emulator as a Mobile browser. You can check this in any controller action: HttpContext.Request.Browser.IsMobileDevice will return false for the Opera Mobile browser. Because the built in DefaultDisplayMode uses the following method to check mobile browsers you need to register your custom DisplayMode which correctly recognizes … Read more

How to specify ContentType for Web API controller method

You’ll have to change the return type of the method to HttpResponseMessage, then use Request.CreateResponse: // GET api/Audit/CSV [HttpGet, ActionName(“CSV”)] public HttpResponseMessage Csv(Guid sessionId, DateTime a, DateTime b, string predicate) { var result = new StringBuilder(); //build a string var res = Request.CreateResponse(HttpStatusCode.OK); res.Content = new StringContent(result.ToString(), Encoding.UTF8, “text/csv”); return res; }

Use of AuthConfig, BundleConfig, FilterConfig , RouteConfig and WebApiConfig in App_Start() folder in MVC

App_Start is just another folder that groups together ASP.NET MVC configuration, which in previous versions of ASP.NET MVC was done in Global.asax. ASP.NET MVC introduces more and more configuration elements, and this folder is ideal to place this configuration. For example, MVC 5’s new auth. configuration, such as for third-party login providers, are also placed … Read more

DataAnnotation for Required property

Okay. Though I have not complete understood this thing. A workaround is found. In Global.asax: GlobalConfiguration.Configuration.Services.RemoveAll( typeof(System.Web.Http.Validation.ModelValidatorProvider), v => v is InvalidModelValidatorProvider); I found it in the Issue Tracker in aspnetwebstack. Here is the link to the page: Overly aggressive validation for applying [DataMember(IsRequired=true)] to required properties with value types If anyone can tell us … Read more

Return custom error objects in Web API

These answers are way more complicated than they need to be. public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Filters.Add(new HandleApiExceptionAttribute()); // … } } public class HandleApiExceptionAttribute : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext context) { var request = context.ActionContext.Request; var response = new { //Properties go here… }; context.Response = … Read more

After upgrading to webgrease 1.5.1.25624 from nuget, System.IO.FileLoadException is coming

Force uninstall the package using Package Manager Console uninstall-package -f WebGrease then install the previous version 1.3.0 using the following command install-package WebGrease -Version 1.3.0 Open your Web.config file and replace below dependency under runtime tag <dependentAssembly> <assemblyIdentity name=”WebGrease” publicKeyToken=”31bf3856ad364e35″ culture=”neutral” /> <bindingRedirect oldVersion=”0.0.0.0-1.3.0.0″ newVersion=”1.3.0.0″ />