Alexander Anikin's blog

My personal blog

Archive for the ‘.Net’ Category

Install bunch of DLL files to Windows Server 2012 GAC

leave a comment »

Thanks to

1. Create ps1 script with contents:

if ( $null -eq ([AppDomain]::CurrentDomain.GetAssemblies() |? { $_.FullName -eq “System.EnterpriseServices, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” }) ) {

[System.Reflection.Assembly]::Load(“System.EnterpriseServices, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”) | Out-Null

$publish = New-Object System.EnterpriseServices.Internal.Publish

Foreach ($file in Get-Childitem “*.dll” -recurse -force)
Write-Host $file

$assembly = $null

if ( $file -is [string] ) {
$assembly = $file
} elseif ( $file -is [System.IO.FileInfo] ) {
$assembly = $file.FullName
} elseif ( $file -is [System.IO.DirectoryInfo] ) {
} else {
#throw (“The object type ‘{0}’ is not supported.” -f $file.GetType().FullName)

if ( -not (Test-Path $assembly -type Leaf) ) {
throw “The assembly ‘$assembly’ does not exist.”

if ( [System.Reflection.Assembly]::LoadFile( $assembly ).GetName().GetPublicKey().Length -eq 0 ) {
throw “The assembly ‘$assembly’ must be strongly signed.”

Write-Output “Installing: $assembly”

$publish.GacInstall( $assembly )

2.  Place it to folder with DLLs and start.

PS You can use set-executionpolicy remotesigned to switch running scripts on.


Written by Alex Anikin

September 13, 2013 at 7:57 am

Posted in .Net, Windows Server

Hacking .Net

leave a comment »

Great video about hacking .Net applications:

More details here:

Written by Alex Anikin

July 10, 2012 at 9:06 pm

Posted in .Net

Making a Request to WebService in Visual Studio from Specific IP address

leave a comment »

Hey all  –


1. I have a web-service refference in my project. I update it time to time. It’s OK.

2. I have several network adapters in my system.

The main thing – I need to call a WebMethod refferenced in my project from specific IP.


As you can see – VS generating class for Web Service Refference and it’s partial. So you can override  some very useful methods. In my case I should override GetWebRequest and change it’s properties. For changing EndPoint I should use ServicePoint.BindIPEndPointDelegate.


public IPEndPoint BindIpEndPointCallbackForIP(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
return new IPEndPoint(_currentLocalIp, 0);

protected override WebRequest GetWebRequest(Uri uri)
HttpWebRequest request = (HttpWebRequest) base.GetWebRequest(uri);
request.Timeout = 10000;
if (_currentLocalIp != null)
request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIpEndPointCallbackForIP);
return request;

I’m trying to make end-point (string in bold) with specific port (ex. 443 or 80), but it fails (why?). And in my case it doesn’t work with IPv6.

Written by Alex Anikin

February 13, 2012 at 2:50 pm

Posted in .Net, C#