A Limitation of Anonymous Classes

Posted by:

Recently, we were editing some code for a client, specifically code that creates a list of an anonymous class, and then runs a LINQ statement on it.

As part of the edit, we had to set the values of this class differently under different conditions. Regardless of the situation, though, the structure would end up the same. We ended up with something similar to this:

If (boolCondition)
var items = itemSourceOne.Select(x => new {id = x.id, value = x.value}).ToList();
else
var items = itemSourceOther.Select(x => ...
Continue Reading →
0

Writing XML in Razor

Posted by:

On one of our recent projects, we needed to add a feature to a client’s website that would dynamically generate XML in a Razor CSHTML file.

In order to do this, we first needed to tell razor that we’re writing XML, which we did by quite simply writing code to set Response.ContentType to XML’s MIME type (text/xml). We also had to set the layout property to be null, to ensure that no HTML from the master pages is added to the ...

Continue Reading →
2

Using Reflection with Dependency Injection

Posted by:

So recently we were working on a large enterprise project that involved Entity Framework 5, Repositories and Dependency Injection. We were working with a previously designed database, so every time we wanted to bring an entity into the project, we needed to create the entity, create it’s code-first map and add the map and the collection to the context. To top that off, we then had to go into our Ninject bindings and add a binding for the repositories.

I noticed ...

Continue Reading →
0

Encryption Error “Length of the data to decrypt is invalid”

Posted by:

So, last week we were beating our heads against a wall trying to figure out why we could not decrypt encrypted XML files supplied by our client along with the decryption algorithm.

We tried to rewrite the decryption method, researched the Rijndael Cryptography, tried other test files. We even encrypted our own files and then decrypted them with ease… so the decryption works. But, no matter what we did, we got the following error trying to decrypt the client supplied files:

System.Security.Cryptography.CryptographicException ...

Continue Reading →
0