Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 46409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:57:41+00:00 2026-05-10T15:57:41+00:00

I have a third party .NET Assembly and a large Java application. I need

  • 0

I have a third party .NET Assembly and a large Java application. I need to call mothods provided by the .NET class library from the Java application. The assembly is not COM-enabled. I have searched the net and so far i have the following:

C# code (cslib.cs):

using System;  namespace CSLib {     public class CSClass     {         public static void SayHi()         {             System.Console.WriteLine('Hi');         }     } } 

compiled with (using .net 3.5, but the same happens when 2.0 is used):

csc /target:library cslib.cs 

C++ code (clib.cpp):

#include <jni.h> #using <CSLib.dll>  using namespace CSLib;  extern 'C' _declspec(dllexport) void Java_CallCS_callCS(JNIEnv* env, jclass cls) {     CSLib::CSClass::SayHi(); } 

compiled with (using VC 2008 tools, but the same happens when 2003 tools are used):

cl /clr /LD clib.cpp mt -manifest clib.dll.manifest -outputresource:clib.dll;2 

Java code (CallCS.java):

class CallCS {     static {        System.loadLibrary('clib');     }     private static native void callCS();     public static void main(String[] args) {         callCS();     } } 

When I try to run the java class, the Java VM crashes while invoking the method (it is able to load the library):

 # # An unexpected error has been detected by Java Runtime Environment: # #  Internal Error (0xe0434f4d), pid=3144, tid=3484 # # Java VM: Java HotSpot(TM) Client VM (10.0-b19 mixed mode, sharing windows-x86) # Problematic frame: # C  [kernel32.dll+0x22366] # ... Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j  CallCS.callCS()V+0 j  CallCS.main([Ljava/lang/String;)V+0 v  ~StubRoutines::call_stub 

However, if I create a plain cpp application that loads clib.dll and calls the exported function Java_CallCS_callCS, everything is OK. I have tried this on both x86 and x64 environments and the result is the same. I have not tried other versions of Java, but I need the code to run on 1.5.0.

Moreover, if I modify clib.cpp to call only System methods everything works fine even from Java:

#include <jni.h> #using <mscorlib.dll>  using namespace System;  extern 'C' _declspec(dllexport) void Java_CallCS_callCS(JNIEnv* env, jclass cls) {     System::Console::WriteLine('It works'); } 

To wrap up:

  1. I am ABLE to call System methods from Java -> clib.dll -> mscorlib.dll
  2. I am ABLE to call any methods from CPPApp -> clib.dll -> cslib.dll
  3. I am UNABLE to call any methods from Java -> clib.dll -> cslib.dll

I am aware of a workaround that uses 1. above – I can use reflection to load the assmebly and invoke desired methods using only System calls, but the code gets messy and I am hoping for a better solution.

I know about dotnetfromjava project, which uses the reflection method, but prefer not to add more complexity than needed. I’ll use something like this if there is no other way, however.

I have looked at ikvm.net also, but my understanding is that it uses its own JVM (written in C#) to do the magic. However, running the entire Java application under its VM is no option for me.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:57:42+00:00Added an answer on May 10, 2026 at 3:57 pm

    OK, the mystery is solved.

    The JVM crash is caused by unhandled System.IO.FileNotFoundException. The exception is thrown because the .NET assembly is searched in the folder where the calling exe file resides.

    1. The mscorlib.dll is in the Global Assembly Cache, so it works.
    2. The CPP application exe is in the same folder as the assembly, so it works also.
    3. The cslib.dll assembly is NEITHER in the folder of java.exe, NOR in the GAC, so it doesn’t work.

    It seems my only option is to install the .NET assembly in GAC (the third-party dll does have a strong name).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 217k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assuming you did not commit the file, or add it… May 12, 2026 at 11:27 pm
  • Editorial Team
    Editorial Team added an answer The Eclipse project has a Windows/WPF implementation of SWT since… May 12, 2026 at 11:27 pm
  • Editorial Team
    Editorial Team added an answer This isn't always a mistake Firstly, just to make things… May 12, 2026 at 11:27 pm

Related Questions

I have a process in a website (Asp.net 3.5 using Linq-to-Sql for data access)
I'm thinking of choosing Adobe AIR as the client-side implementation technology for an upcoming
I have a .NET assembly that contains classes to be registered as ServicedComponent through
How do I make instances of and calls to COM components that have been

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.