My Software Notes

Useful things I discover

Archive for the ‘Tips and Tricks’ Category

Forcing Visual Studio to produce an XML Serializers DLL

leave a comment »

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.

Quick answer:

After setting the above project property you must go into the project file in your favorite text editor and add this:

<SGenUseProxyTypes>false</SGenUseProxyTypes>

 

just after the line:

<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>

 

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.

Written by gsdwriter

July 28, 2014 at 11:39 am

Environmental Variables Disappearing In Windows

leave a comment »

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.

Written by gsdwriter

October 31, 2013 at 12:05 pm

List RSA Key Container Names

with 6 comments

Recently I’ve been looking into encrypting sections of web.config on a couple of web sites that reside on a web farm.

It’s not very difficult (once you figure out how to get around the fact that some of the instructions don’t work) and I’ll write another post on it once I’ve finished implementing it. But there is one major weak point: What happens if you forget the name of the key you are using?  Where do you go to find the names of the RSA keys?

You’d think that listing the names of RSA key containers would be simple.  After all, they are real easy to create just type:

aspnet_regiis -pc "MyKeys" -exp

(aspnet_regiis can be found in C:\WINDOWS\Microsoft.Net\Framework\v2.0.50727  or higher)

It’s so simple to do and yet if you forget the name you used then finding it again is virtually impossible.

After many, many searches on Google, Bing and DuckDuckGo, I finally found something that will list them.  (Surprisingly it was highest on the DuckDuckGo search and that’s how I found it.)

It’s a simple open source app called KeyPal.  Download it, open up a command prompt and run it.  At start up it gives you a list of user keys, a list of commands and a blank prompt (with no “>” or anything to indicate it’s a prompt).  To list machine level key containers just type “LM”, press Enter and there they are!

There is probably something in the bowels of Windows that will also do this, but I couldn’t find it after searching and searching, so kudos to the guys at JavaScience who wrote KeyPal.

I hope this gets onto search engines to help other poor slobs like me find out how to list RSA Key Container names without spending hours hunting.

Written by gsdwriter

August 6, 2012 at 12:08 pm

Replacing Notepad.exe

leave a comment »

You want to use your favorite text editor rather than Notepad.  It seems like you could just rename the exe of your favorite to “notepad.exe” and drop it into the Windows directory.  But it won’t work.

First your favorite text editor may not be composed of just one exe file.  Second Windows regards Notepad as part of its installation and Windows Protection will overwrite your text editor at some point.

But there is a way to do it and here it is:

(I’m using Notepad++ as my example text editor. You can alter the various paths and file names to suite your own situation.)

1. Create a cmd file containing these two lines:

@echo off 
start "" "C:\Program Files (x86)\Notepad++\notepad++.exe" %2 %3 %4 %5 %6

Save it in the Notepad++ folder. Call it npplauncher.cmd

2. Open regedit and navigate to:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\

3. Add a key under “Image File Execution Options”. Name the key “notepad.exe”.

4. To the key add a string value with the name “Debugger” and the value “C:\Program Files (x86)\Notepad++\npplauncher.cmd”.

That should do it.  Now just double-click a txt file or type “notepad myfile.txt” at the command line and your text editor will open instead of Notepad.

FAQs:

Q: Why do we drop %1 in the cmd file? 

The command line you use when you attempt to run your text editor will look something like “notepad myfile.txt”.  This entire command line is passed to npplauncher.cmd and the first parameter will be “notepad”, which you don’t want to open in your text editor, so we drop it.

Q: Why do you have an empty string as the first parameter to the start command?

If the first parameter to start has quotes around it then start treats it as the title of the window that it will open.  If you omit the empty string then “C:\Program Files (x86)\Notepad++\notepad++.exe” will be treated as a title and not as a program to run.  Here is where I found this: http://stackoverflow.com/questions/154075/using-the-dos-start-command-with-parameters-passed-to-the-started-program

Q: Why do you put the editor’s name into the “Debugger” string value?

It launches the application you’ve named as the debugger for the application named in the key.  I.e., “C:\Program Files (x86)\Notepad++\notepad++.exe” is regarded as the debugger for “notepad.exe”.  For a much better explanation see this: Replacing Windows Applications – the Safe Way.

Q: Why do I need the npplauncher.cmd file?

You can get around it if your editor has a way for you to ignore the first parameter.  The only reason for the cmd file is to ignore that first parameter.  See the “Replacing Windows Applications – the Safe Way” article I linked to ealier for details.  I guess another reason for the cmd would be if there are other things you want to do to the command line before passing it on to the text editor, e.g., for Notepad++ you could add the -multiInst parameter.

Q: Why do you have %2 through %6 in your cmd file?

I just decided to pass up to 5 parameters.  If you want more then add more.  If you want to get really fancy then you can probably find some crazy DOS command that will allow you to pass the entire command line minus the first parameter.

Q: I use Notepad++ and I want to use the -multiInst parameter.  How do I do that?

Just put -multiInst before the %2 in the cmd file.

start "" "C:\Program Files (x86)\Notepad++\notepad++.exe" -multiInst %2 %3 %4 %5 %6

Summary

So that’s it.  Pretty easy really, once you know.

Other references:

http://sourceforge.net/projects/notepad-plus/forums/forum/331753/topic/3435863

 

Written by gsdwriter

July 11, 2012 at 3:11 pm