Showing posts with label x64. Show all posts
Showing posts with label x64. Show all posts

Friday, October 9, 2009

Export native 64bit method from .NET assembly

It is well known fact that .NET assembly could be tweaked to export native method, similar way how normal DLLs do it. There is good description and tool from Selvin for 32bit native function.
My problem was how to do it for 64bits. Here you go.

1) you IlDAsm your assembly into il code.
2) Edit the IL and change header to look like this
for 32bit
.corflags 0x00000002
.vtfixup [1] int32 fromunmanaged at VT_01
.data VT_01 = int32[1]
for 64bit
.corflags 0x00000008 
.vtfixup [1] int64 fromunmanaged at VT_01
.data VT_01 = int64[1]
3) Header of your exported method would look similar to this. This is same for 32bit version.
.vtentry 1 : 1
.export [1] as Java_net_sf_jni4net_Bridge_initDotNet
4) You IlAsm the file back into DLL. For x64 you use /x64 flag.

Hack ReSharper for x64 unit tests

If you need to develop 64bit .NET application and run unit tests with R#, you will find that it's not possible, because Visual Studio is 32bit process and R# task runner is loaded as 32bit as well. There is quick and dirty solution to that.

1) Stop Visual Studio
2) Find JetBrains.ReSharper.TaskRunner.exe
3) Drop read-only flag on the file
4) Run
CorFlags.exe JetBrains.ReSharper.TaskRunner.exe /32BIT- /Force


The assembly have now broken signature and VS/R# complains about that. But now you could debug your 64bit unit tests. More info would be probably here