New transaction is not allowed because there are other threads running in the session execption with federation services

Though it sounds like a crazy error, the actual problem has nothing to do with threads, as per this Connect bug filing

https://connect.microsoft.com/VisualStudio/feedback/details/612369/misleading-error-message-in-sqlexception-when-using-entity-framework

Simple fix is, if you are doing a for loop for any collection of entities, make sure you convert the collection to list or array by using .ToList() or .ToArray() and loop that collection, and error does not appear.

Simple isn’t it?

A potentially dangerous Request.Form value was detected from the client

You usually get this error when you are trying to send HTML content from MVC application to Entity Framework. Go the the class that has this issue under Edmx, and add [AllowHtml] attribute above the class attribute that should accept HTML content from MVC view.

using System.Web.Mvc;
public partial class SchoolMessage
{
public System.Guid Id { get; set; }
public string Subject { get; set; }
[AllowHtml]
public string Message { get; set; }
}

Hope that helps :)

(Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Most often when you checkout old git repo or your own code stashed for months, and compile, you will encounter this exception

(Exception from HRESULT: 0x80070057 (E_INVALIDARG))

This could be because project can’t find references or some other updated dlls are not causing issue with ones already in a compiled code.

Simplest way to fix this is to .. delete the ‘bin’ and ‘obj’ folders of the project and if it is web project, delete ‘Temporary ASP.NET Files’

Hope that helps :)

Unable to retrieve metadata for ‘some entity class’. Unable to load the specified metadata resource.

Sometimes when we are using Entity Framework with MVC, we update the datamodel to add/update/remove entities. When we try adding controller, we get the following error.

There was an error running the selected code generator:

‘Unable to retrieve metadata for ‘some entity class’. Unable to load the specified metadata resource.’

Easiest fix for this, in web.config, for the database connection string, you will find the string as below

metadata=res://*/ModelName.csdl|res://*/ModelName.ssdl|res://*/ModelName.msl;provider=

Replace it with

metadata=res://*/;provider=…

Compile once and retry adding the controller.

This is quick fix and works :)

P.S. Ideally we should remove the connectionstring and edmx file and add it again to make it work.

Windows Phone emulators stuck at ‘OS is loading’ or ‘Loading Operating System’ or ‘Windows Phone OS is starting…’

Many a times, Windows Phone Emulators fail to launch and usually are stuck at ‘OS is loading’ or ‘Loading Operating System’ or ‘Windows Phone OS is starting…’. Simple fix for this is to go to ‘Control Panel’ -> ‘System and Security’ -> ‘Windows Firewall’ -> ‘Allow app or feature through Windows Firewall’, and add app found at C:Program Files (x86)Microsoft XDE<version>XDE.exe to allow list.

Simple isn’t it?

 

Don’t let your server response headers reveal too much about your server!

On every request on API or a website, your server sends some information that might hurt your servers, if vulnerabilities are discovered on specific version of IIS, MVC version, .Net framework. Below are sample response headers that reveal too much about your server.

Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

Lets figure out a way to hide them

Server: Microsoft-IIS/8.0

Add these lines to global.asax

protected void Application_BeginRequest(object sender, EventArgs e)
{
var application = sender as HttpApplication;
if (application != null && application.Context != null)
{
application.Context.Response.Headers.Remove(“Server”);
}
}

X-AspNetMvc-Version: 4.0

If it is MVC / MVC WebAPI project reveals  You can hide it by adding these lines in Global.asax 

protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
}

X-AspNet-Version: 4.0.30319

Add these lines to Web.Config

<system.web>
<httpRuntime … enableVersionHeader=”false” /> …

 X-Powered-By: ASP.NET

Add these lines to Web.Config

<system.webServer>
<httpProtocol>
<customHeaders>
<remove name=”X-Powered-By” />
</customHeaders>
</httpProtocol>

Hope that helps :)

[Issue => Fix] Stuck at Authenticating with the iTunes Store

Many a times, while pushing the iOS app to Apple App Store, when we use Application loader, we get stuck at message ‘Authenticating with the iTunes Store.

Quickest fix for this is to copy ‘Application Loader’ app from ‘Applications’ to desktop, and simultaneously running both ‘Application Loader’ apps, one from ‘Applications’ folder and one from desktop to publish to app store. This works like charm every time.

Hope that helps!