Tuesday, October 27, 2009

How to find Regasm.exe and use it in a .Bat file

I need to use RegAsm.exe to register several assemblies in a .bat file; however, since RegAsm.exe is not in the system path, it is difficult to just use like Regsvr32 which is always in the system path. I suppose the reason for this is that there can be multiple .NET Frameworks installed and you need to use the correct one.

You can use the WINDIR enviroment variable to get the root of the path. It will probably be something like:

C:\WINDOWS

You then need to add "\Microsft.NET\Framework\" to the path, and finally the path to the specific .NET Framework you are using:

SET fwpath="%windir%\Microsoft.NET\Framework\v2.0.50727"

%fwpath%\regasm.exe app.dll

How to pass TARGETDIR with CustomActionData and not get an Error

Maybe it is just me, but it seems like everything I need to do with an MSI setup is never as easy as it should be. Here is just an other example.

I need to pass the Target Directory for the installation to the InstallClass that I am using in the MSI Custom Actions (I have to do this because of other things in the MSI that don't work like they should). However, when I define the CustomActionData as:

/targetPath=[TARGETDIR]

or

/targetPath="[TARGETDIR]"


I get the following error:

Error 1001. Exception occurred while initializing the Installation:System.IO.FileNotFoundException


The solution I have found is to say this:

/targetPath="[TARGETDIR]\"

I found this info from the following post:

http://www.dotnet247.com/247reference/msgs/35/179584.aspx


I later found the Microsoft documentation on solving the problem:

http://msdn.microsoft.com/en-us/library/2w2fhwzz(VS.71).aspx

Thursday, October 22, 2009

Import an Excel File with VB.NET

Here is a simple solution for importing an Excel file into VB.NET using an OleDbConnection:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_22487951.html

Wednesday, September 16, 2009

Some Good Examples of MemoryStream in C#

Here are several good examples of using MemoryStream in C#:

http://www.java2s.com/Code/CSharp/File-Stream/CreateaMemoryStream.htm

Formatting DateTime in C#

Here is an excellent list of the C# Formatting specifications for the DateTime type. The VB.NET formatting could easily be derived from this post as well:

http://www.csharp-examples.net/string-format-datetime/

Monday, September 14, 2009

How to Save a Bitmap as a 1BPP (bitonal) TIFF File in .NET

If you try to use the EncoderValue.CompressionCCITT4 value to save a Bitmap out as a 1 BPP Tiff file, you will get an error "Invalid Parameter Value". It turns out that .NET can't go from an RGB to a Bitonal image with the Save method on a Bitmap (no matter how you set the encoder parameters). The following posting by Michael McCloskey solves the problem:

http://www.codeproject.com/KB/GDI-plus/BitonalImageConverter.aspx?msg=2020403


Easy to use and runs quickly.

Thursday, September 3, 2009

My Trials and Tribulations getting a WCF Service running on 64 bit Windows Server 2008 with 32 bit Native Dlls

My WCF Service uses a native DLL written in C++. This native Dll can be 32 bit or 64 bit. The 32 bit version relies on other 3rd party Dlls that are not available in 64 bit. And the 64 bit version is the same thing without the 3rd party dependencies.

1. IIS 7 is easy enough to work in 32 bit or 64 bit mode (on a 64 bit Windows Server 2008 server). By default, the application pool is 64 bit, but you can create another application pool for 32 bit applications or change the default application pool to 32 bit by using the “Enable 32-bit Applications” switch under Set Application Pool Defaults. Then on the Advanced Setting page for your WCF Services Virtual Directory, you can select the Application Pool to use. More Info: http://blogs.msdn.com/rakkimk/archive/2007/11/03/iis7-running-32-bit-and-64-bit-asp-net-versions-at-the-same-time-on-different-worker-processes.aspx

2. The \Windows\System32 directory is for 64 bit files on a 64 Bit OS. And SysWow64 contains the 32 bit files. (Windows on Windows 64 bit). Confusing, but once you know, you know.

3. Getting a 32 bit app using MFC with shared DLLs running on a 64 bit OS can give you a funny error: “The application has failed to start because its side-by-side configuration is incorrect”. The 64 bit OS doesn’t get the standard 32 bit MFC Runtime dlls installed. So you can deliver the 32 bit dependencies or just recompile the DLL using MFC in a Static Library. Easy to fix either way, but the error message is not so obvious. More Info: http://www.eggheadcafe.com/conversation.aspx?messageid=31209382&threadid=31189019

4. The WCF Service always runs fine on the development machine. Deploying it to a real IIS server then has various difficulties to overcome. Mostly, the problem is with security and permissions. If you get: “The caller was not authenticated by the service.” You can possibly just change the binding from wsHttpBinding to basicHttpBinding in the web.config file. Here is more discussion on the issue: http://stackoverflow.com/questions/284538/wcf-error-the-caller-was-not-authenticated-by-the-service