How to combine multiple Uri in C# and VB.NET

To combine multiple Uri in C# and VB.NET you can use the following snippet.

Simple Sample (combining 2 uri)

Sample C#

public string CombineUri(string uri1, string uri2)
	if (uri1.Length == 0){return uri2;}
	if (uri2.Length == 0){return uri1;}
	uri1 = uri1.TrimEnd('/', '\\');
	uri2 = uri2.TrimStart('/', '\\');
	return string.Format("{0}/{1}", uri1, uri2);

Sample VB.NET (autogenerated)

Public Function CombineUri(uri1 As String, uri2 As String) As String
	If uri1.Length = 0 Then
		Return uri2
	End If
	If uri2.Length = 0 Then
		Return uri1
	End If
	uri1 = uri1.TrimEnd("/", "\")
	uri2 = uri2.TrimStart("/", "\")
	Return String.Format("{0}/{1}", uri1, uri2)
End Function

UPDATE 23.06.2015

Combine multiple Uri

Since this snippet is one of our most read snippets of all time, i decided to upgrade this snippet.
This method now uses params string[] as method parameter which allows much more uri strings to be combine at once.

Sample C#

public string CombineUri(params string[] uriParams)
	var retVal = string.Empty;
	foreach (var uriParam in uriParams)
		var tempParam = uriParam.Trim();
		if (!String.IsNullOrEmpty(tempParam))
			tempParam = uriParam.TrimEnd('/', '\\');
			retVal = !String.IsNullOrEmpty(retVal) ? string.Format("{0}/{1}", retVal, tempParam) : string.Format("{0}", tempParam);
	return retVal;

Sample VB.NET (autogenerated)

Public Function CombineUri(ParamArray uriParams As String()) As String
	Dim retVal = String.Empty
	For Each uriParam As var In uriParams
		Dim tempParam = uriParam.Trim()
		If Not [String].IsNullOrEmpty(tempParam) Then
			tempParam = uriParam.TrimEnd("/"C, "\"C)
			retVal = If(Not [String].IsNullOrEmpty(retVal), String.Format("{0}/{1}", retVal, tempParam), String.Format("{0}", tempParam))
		End If
	Return retVal
End Function

For more informations about params see the msdn: params (C# Reference)

How to get the BuildDate of a Assembly in C# and VB.NET

Sample C#

public DateTime GetBuildDate(Assembly assembly)
	var location = assembly.Location;
	const int headerOffset = 60;
	const int linkerTimestampOffset = 8;
	var buffer = new byte[2048];
	Stream stream = null;

		stream = new FileStream(location, FileMode.Open, FileAccess.Read);
		stream.Read(buffer, 0, 2048);
		if (stream != null)

	var i = BitConverter.ToInt32(buffer, headerOffset);
	var secondsSince1970 = BitConverter.ToInt32(buffer, i + linkerTimestampOffset);
	var dt = new DateTime(1970, 1, 1, 0, 0, 0);
	dt = dt.AddSeconds(secondsSince1970);
	dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
	return dt;

Sample VB.NET

Public Function GetBuildDate(assembly as Assembly) As DateTime
	Dim location = assembly.Location
	Const  headerOffset As Integer = 60
	Const  linkerTimestampOffset As Integer = 8
	Dim buffer = New Byte(2047) {}
	Dim stream As Stream = Nothing

		stream = New FileStream(location, FileMode.Open, FileAccess.Read)
		stream.Read(buffer, 0, 2048)
		If stream IsNot Nothing Then
		End If
	End Try

	Dim i = BitConverter.ToInt32(buffer, headerOffset)
	Dim secondsSince1970 = BitConverter.ToInt32(buffer, i + linkerTimestampOffset)
	Dim dt = New DateTime(1970, 1, 1, 0, 0, 0)
	dt = dt.AddSeconds(secondsSince1970)
	dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours)
	Return dt
End Function

How to use the assembly InternalsVisibleTo attribute

If your code contains classes, interfaces or structs that have the internal (c#) access qualifier or the Friend (VB.NET) access qualifier, you cannot access them from another assembly (e.g. unit testing). Types have this qualifier for one of two reasons

– You have explicitly marked them as internal.
– By default, top-level classes, interfaces, or structs that have no explicit access qualifier are treated as internal.

But what if you need to make them visible just for a specific assembly? Thats where the assembly InternalsVisibleTo attribute comes into play.
If your Assembly which has the Internal access qualifiers has no strong name you simply have to put the following line of code to its AssemblyInfo-File.

Sample C#


Sample VB.NET


If your Assembly which has the Internal access qualifiers has strong name you simply have to put the following line of code to its AssemblyInfo-File.
The PublicKey depends on your Assembly, so you need to put the right PublicKey in it, check the links on the bottom of this Posts on how to get the PublicKey.

Sample C#


Sample VB.NET


More informations: Setting the InternalsVisibleTo Attribute, Getting Public Key Token of Assembly Within Visual Studio, AssemblyHelperTool