vicker313 tech blog

February 28, 2010

How to Allow Access of Internal Class in Another .Net Assembly

Filed under: .Net — Tags: , , , — vicker313 @ 8:00 am

We always create separate assemblies so that we can reuse some of the classes, and declare the classes as public so that can be accessed by other assemblies. However this will allow other people to use the assemblies that we created. To protect our assemblies to be assessed by our owned assemblies only, we can declare the classes as internal and do the following setup:

For the assembly that will access your shared assembly

  1. Use SN utility to create a new key pair and save it in an out put file (key.snk). SN is available in .Net SDK.
    sn -k key.snk
  2. Use your .Net IDE (either Visual Studio or Sharpdevelop) to sign the assembly with the key file (key.snk).
  3. Compile the assembly.
  4. Use SECUTIL to extract the strong name information from the assembly (usually in the bin\debug directory in you project folder) in hex string format and save it to a text file (strong.txt). SECUTIL is also available in .Net SDK.
    secutil -hex -s application.exe > strong.txt
  5. Inside the strong name file (strong.txt), you can see a long hex string, copy it (remember to exclude the first 2 character 0x)

For the shared assembly

  1. Use SN utility to create a another key pair and save it in an out put file (key1.snk).
    sn -k key1.snk
  2. Use your .Net IDE (either Visual Studio or Sharpdevelop) to sign the assembly with the key file (key1.snk).
  3. Open AssemblyInfo.cs, (or AssemblyInfo.vb, depend on the language that you used)
  4. Be sure System.Runtime.Compiler.Services is imported:
    using System.Runtime.CompilerServices;
  5. Go to last line of the file, add the following line (ProgramName is the name of you referring assembly and hexstring is the hex string that you copied from the strong name file just now)
    [assembly: InternalsVisibleTo("ProgramName, PublicKey=hexstring")]
  6. Compile the assembly.

Now you should able to refer the shared assembly and use the internal classes.

You might not need to install SDK to get SN or SECUTIL, try google around should able to find some download links.


August 28, 2009

How to Download Microsoft Web Platform Products

Filed under: .Net — Tags: , , — vicker313 @ 8:27 am

Microsoft Web Platform is a web installer software for products like:

  1. Visual Web Developer
  2. SQL Server Express
  3. Silverlight Tools
  4. IIS and ASP.NET Extensions and others

My target is download SQL Server Express 2008 installer and do a offline install. This is how it works:

  1. Go to MSDN download page.
  2. Download and install Microsoft Web Platform.
  3. Then choose to install SQL Server Express 2008 from the download page, skip the register and continue.
  4. Web Platform should be auto executed, then close the Web Platform.
  5. Go to C:\Documents and Settings\[User]\Local Settings\Application Data\Microsoft\Web Platform Installer
  6. Open a file called productCache2.0.0.5.xml using your favorite editor.
  7. Look for the <installerItems>, each product mentioned above should have 1 of these tags so you need to pick the one you want to install. For SQL Server Express 2008, you can see something like <eulaURL></eulaURL&gt;.
  8. Check out the <installerURL> tag, which contain the installer actual URL, for SQL Server Express 2008 it is
  9. Download the installer using the URL you found, then double click it to install the product.

To offline install Visual Studio Express without download the whole image file, you might refer here.

June 13, 2009

Use Firebird as standalone application database

Filed under: .Net, Firebird — Tags: , , — vicker313 @ 8:33 am

Choices of database in doing a standalone application always limited to me. Some people might use MYSQL, MSSQL or even Oracle as database, but to me:

  1. It is not logical to use a server based database for a standalone application
  2. You will need to install the database in order to deploy the application, where some settings might not understandable to non technical personnel.

So all the while I am using MS Access as database for standalone application, but still you need to install Microsoft Data Access Components (MDAC) if the PC you deploy doesn’t have MS Access or Office installed.

But now I am using Firebird as database, which you don’t need to install the extra stuffs, just copy over the whole folder to finish the deployment (Literally standalone). Here are some guidelines to use Firebird in .Net:

  1. Go to Firebird website and download 2 things: database embeded edition (which is in zip format) and .Net FirebirdClient library (in zip format as well).
  2. Extract following files from the database zip file to your project folder (under bin\debug or bin\release):
    1. fbembed.dll
    2. firebird.conf
    3. firebird.msg
    4. icudt30.dll
    5. icuin30.dll
    6. icuuc30.dll
  3. Extract FirebirdSql.Data.FirebirdClient.dll to your project folder (under bin\debug or bin\release).
  4. Add reference of FirebirdClient to your project, and you can start using it.
  5. The methods to use FirebirdClient more or less is the same as other Data class, while the connection string is:
    servertype=1;user=<admin>;password=<password>;dialect=3;database=<database location>

May 21, 2009

SharpDevelop, a replacement to Visual Studio

Filed under: .Net — Tags: , , — vicker313 @ 7:48 am

I have been playing around with programming for a long time, and VB6 is my very first language to do project for real customer. At that time, the only option of IDE to be used was of course Visual Studio.

When it came to the era of Dot Net Framework, class and object got inside the picture and I started to explore C# programming (which is more Object Oriented if compare to VB.Net). Still I was using Visual Studio.

What I don’t like about Visual Studio is that: first the cost, second it installs a lot of things that I don’t want (or don’t understand). So I started to search for an alternative which I found SharpDevelop. Actually SharpDevelop is purposely for C# programming, however you can also code VB.Net using it (even F# in the newest version). As Dot Net evolves from 1.0 to 3.5, SharpDevelop is developed into 3 different version: 1.0, 2.0 and 3.0. What’s so great about this little program is that: firstly it is open source and free, secondly it is small (relatively compare with Visual Studio). When you install SharpDevelop, it doesn’t like installing Visual Studio, make you feel like upgrading your windows.

Well bad things for SharpDevelop (my personal opinion) is that the reporting system doesn’t really fit my requirement. But since it is free and small, easy to install and uninstall, I think every C# and VB.Net programmer should take a look and give it a try (It can open project save in Visual Studio).

November 26, 2008

How to offline install Visual Studio Express without download the whole image file

Filed under: .Net — Tags: — vicker313 @ 1:46 am

Visual Studio Express (VSE) is the free version of Visual Studio, released together with Visual Studio 2005 and 2008. User can get VSE from MSDN website without any genuine checking. There are two ways in getting VSE.

The first method is web install, which the user needs download a bootstrap of a selected VSE product, run it and the bootstrap will automatically download setup files from internet and install the product into the computer. The next time user wants to install the software in another computer, the bootstrap will download the whole things again from the internet in order to perform the installation.

The other method is of course offline install, which user needs to download the whole image file from the internet, and either burn it or virtual it in order to perform the installation. However the image file consists of everything (Visual Studio Web Developer, C#, Visual Basic, SQL Server, framework and other stuffs), and making it more than 700MB (which a normal CD cannot hold).

In my scenario, I want to download Visual Studio Web Developer Express only, and will install the software in another computer without any internet connection. I don’t want to download the whole image file that I might just be using 10% of the files. There isn’t any official way to download a single product of VSE, so we need to play around with the bootstrap in order to download a workable offline installation file.

First, download your selected product bootstrap. And then we need to extract the bootstrap into a directory using some compression tool like WinRAR.

Second, we search for a file called baseline.dat inside the directory and open it with notepad or other editor. Then we search for a section called [vs_setup.dll] (it is square bracket). Under that section, you can find a URL parameter with the value of fwlink…

Third, open a browser and type in followed by the URL value that found in baseline.dat at the address bar (as a result your address will look like…). It will automatically download the installation file of that product. It is usually about 50MB.

Forth, after we download the installation file, we extract the file into another directory. There will be a file called vs_setup.msi. Then we need to run a command prompt, go to that directory, and use the command below to execute the installation file.

msiexec /i vs_setup.msi vsextui=1 addlocal=all reboot=reallysuppress

If we run the file vs_setup.msi directly, there will be an error to request you to run the setup.exe file. So at the command, vsextui=1 make the installation think it is executed through a setup.exe file.

However when I try out the trick for VSE 2005 product, there is a little difference in the forth step. Instead of extract the installation file into another directory, I extract it to the same directory as I extract the bootstrap. Then I can install the product by using the setup.exe from the bootstrap.

And that’s about it in how to offline install VSE without download the image file. I have used this trick to install VSE Web Developer 2005, Web Developer 2008 and C# 2008.

To install SQL Server Express 2008, you might refer here.

Blog at