Another thing I do infrequently is encrypt and decrypt web.config sections. I end up going back to a script I wrote ages ago to find the command lines.
So just to save time, here they are:
Encrypt a web.config section
“c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe” -pef sectionName sitePath
“c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe” -pef “connectionStrings” “c:\websites\mysite”
Decrypt a web.config section
“c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe” -pdf sectionName sitePath
“c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe” -pdf “connectionStrings” “c:\websites\mysite”
These command lines must be run on the web server and must be run in a console with admin privileges.
I don’t have to deal with covariance and contravariance very often, so every time I do I forget which is which. So, just for my own benefit, here is a note describing them:
Covariance and contravariance are terms that refer to the ability to use a less derived or more derived type than originally specified.
Covariance – Enables you to use a more specific type than originally specified
E.g., in generics
We have a base type called “Feline” and we have a derived type called “HouseCat”.
IEnumerable<HouseCat> cats = new List<HouseCat>();
IEnumerable<Feline> gods = cats;
//Note: felines have a very high opinion of themselves :)
Contravariance – Enables you to use a less derived type than originally specified.
E.g., in generics
Using the same base and derived types as above.
IEnumerable<Feline> gods = new List<Feiline>();
IEnumerable<HouseCat> cats = gods;
Just a note to self.
The Contains method on String when used in an Entity Framework “where” clause is case insensitive.
Assume the “NoteContent” column on the table “Notes” is a varchar column. If I run the following Linq query against the database where db is a DbContext then I get the same result every time.
var num = db.Notes.Where(n => n.NoteContent.Contains(“NoTe”)).Count();
var num = db.Notes.Where(n => n.NoteContent.Contains(“NOTE”)).Count();
var num = db.Notes.Where(n => n.NoteContent.Contains(“note”)).Count();
All produce the same value for “num”.
I’m making this note to self because I keep forgetting and because I keep seeing people do this:
var someString = “whatever”;
var num = db.Notes.Where(n => n.NoteContent.ToUpper().Contains(someString.ToUpper())).Count();
And, to quote Led Zepplin, “It makes me wonder.”
A friend needed the Xml Serializers dll, the one named something like “ClassLibrary1.XmlSerializers.dll”, so he went into the project properties in VS and set “Build > Generate serialization assembly” to “On”. But nothing happened. No XmlSerializers dll was created.
We hunted round for an answer and came across this: Generating an Xml Serialization assembly as part of my build.
After setting the above project property you must go into the project file in your favorite text editor and add this:
just after the line:
You should end up with something like this:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies> <SGenUseProxyTypes>false</SGenUseProxyTypes> </PropertyGroup>
Do that for every build configuration where you need the serializer.
Hope that helps.
If you ever see Entity Framework code that looks something like this:
SELECT 1 AS [C1], CAST(NULL AS int) AS [C2], CAST(NULL AS int) AS [C3], CAST(NULL AS varchar(1)) AS [C4] FROM ( SELECT 1 AS X ) AS [SingleRowTable1] WHERE 1 = 0
and your EF LINQ query was nothing like it (and who’s would be?), then you probably have a
in your query and the collection “somelist” is empty.
I hit this today and was scratching my head until I found this:
Hope that helps someone.
I started noticing it a couple of days ago: icons on my task bar, such as the File Explorer, stopped working and gave me that annoying “application cannot be found” message. Other programs just stopped working.
I hunted around and found that my PATH variable in a console window was only listing the additional path items from the “User” environment. The “System” (aka “Machine”) PATH environmental variable was not being appended to the front of the “User” PATH.
I tried to open “Computer > Properties > Advanced Properties” and it said it couldn’t find the Advanced Properties dialog and it gave the path to the app using “%windir%”. So I opened up a console and typed “SET” and the majority of the System environmental variables were missing.
What was going on?
I hunted and hunted and finally found this: Windows 7’s PATH and environment variables are corrupted.
Can you believe that? When your path goes over 2048 characters long the entire environmental variables handling in Windows goes haywire.
I edited my PATH and took out a bunch of duplicate entries (what added those?), got it down to a much smaller size and suddenly my Win7 machine was working perfectly again.
It seems like a serious omission that Windows gives no warning at all that there is a problem and we poor buggers have to figure out what to do.
I hope this post helps someone out there with the same headache.
If you are running Windows 8 then mounting ISO images is built in.
If you are running an earlier Windows version then you need software. The simplest I’ve found is Virtual CloneDrive. There are others that people seem to like, such as MagicISO and DaemonTools, but you aren’t supposed to install their free versions for commercial use, but Virtual CloneDrive is completely free and works great.
BTW: Don’t even think of using Microsoft’s Virtual CDRom Control Panel – it works on XP, but not on anything later without jumping through so many hoops that your legs will give way.