Click here to Skip to main content
13,356,318 members (62,882 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 25 Feb 2011

Calling a J# DLL from .NET 4.0

, 25 Feb 2011
Rate this:
Please Sign up or sign in to vote.
Calling a J# DLL from .NET 4.0


When you call a J# DLL from .NET 4.0 (or later) code, you will get an error that vjsnativ.dll could not be located. The work-around to date has been to copy vjsnativ.dll to the directory of the primary application calling the code. For an app, this is workable although a bit of a pain. But for web apps, this can be very problematic as you're talking the underlying web server.

It turns out there's a much easier approach. The following code needs to be called in your C# code before instantiating any classes or calling any code in a J# DLL. After you call this, you can then call all of your J# code. The trick is simple – you load the library explicitly and then Windows already knows its location.


using System;
using System.IO;
using System.Runtime.InteropServices;
using net.windward.api.csharp;
namespace TestNet40
class Program
[DllImport("kernel32", SetLastError = true)]
static extern IntPtr LoadLibrary(string lpFileName);
static void Main(string[] args)
if (Environment.Version.Major > 4)
string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"..\Microsoft.NET\Framework\v2.0.50727");
folder = Path.GetFullPath(folder);
LoadLibrary(Path.Combine(folder, "vjsnativ.dll"));
// now call J# code

Calling It

The best approach is if you can place this in your initialization well before you make any calls to any J# libraries. That way, you don't need to check before each call.
Originally posted at Calling J# code from .NET 4.0


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

David Thielen
Chief Technology Officer Windward Studios
United States United States
CTO/founder - Windward Studios

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 25 Feb 2011
Article Copyright 2011 by David Thielen
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid