Attempt by security transparent method failed

If you are seeing the following:

Attempt by security transparent method ‘Microsoft.Web.Mvc.ScriptExtensions.Script(System.Web.Mvc.HtmlHelper, System.String)’ to access security critical type ‘System.Web.Mvc.MvcHtmlString’ failed.

or something similar chances are you’ve recently updated your project from MVC 4 to 5 and didn’t update all the references in nuget to target the new version. In my case the MVC4Futures nuget package should be removed and the Microsoft.AspNet.Mvc.Futures package should be used instead.

Read More

I’ve got PDB’s but no line numbers

Recently ran into an issue where we wanted to get line numbers from exception stack traces that are being logged for a clients site. We followed all the instructions we found online but nothing got us what we wanted. We had PDBs for all our DLLs in the bin folder, we tried deploying a full debug version but nothing got us what we wanted. After many searches we came across a mention that if you are having your app impersonate (which we are not) to make sure the account that is being impersonated is a member of the Debugger Users group. Since we are using a custom App Pool Identity we decided it was worth a shot and made the change in AD. Voilà! We’ve got line numbers in our logs and now I can finally fix that pesky null reference exception.

Why it works

There’s more knowledgeable people out there that can explain it better but from my understanding when an exception is thrown and you access the stack trace a debugger instance of sorts is ran on the matching PDB and if the current user does not have correct permissions to perform this action the PDB can’t be processed and you just get minimal information.

Read More

SQLite and DateTime Columns

Just a heads up, if you’re storing dates into a SQLite database using C# make sure your DateTime has the correct DateTime.Kind set otherwise it will default to GMT. Either use DateTime.UtcNow or set the kind after the fact by calling DateTime.SpecifyKind like so:

var someDate = DateTime.Parse('01/13/1981 12:30:00');
var utc = DateTime.SpecifyKind(someDate , DateTimeKind.Utc); // now we are UTC

Read More