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

  • SEARCH
  • Home
  • 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 7015185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:37:08+00:00 2026-05-27T22:37:08+00:00

I getting bug: crash happened outside the Java Virtual Machine in native code .

  • 0

I getting bug: crash happened outside the Java Virtual Machine in native code. whenever i run with class file with native library and .net module file it works fine.
but when i try to run alone class file and native library it gets crash .please clarify my mistake i have done, please review my code.
for your reference with parameter

==========================================

 public class Sum
    {
        public int add(int a, int b)
        {
            return a + b;
        }
    }

===========================================

save as Sum.cs and compile it to module
using cmd:

csc /t:module sum.cs

Create Java File to test

===========================================

public class test{
public native int add(int a,int b);
 static {
        System.loadLibrary("JSample");
    }

    public static void main (String[] args) {
       System.out.println(new test().add(10,15));
    }
}

==========================================

save it as test.java compile as

javac test.java

create native header file

javah -jni test

it will create test.h

create win32 project using visual studio (I used VS2010)
Choose project name as JSample

include header and C#.net module
write header for manged C++ conversion

==============================================

#using <mscorlib.dll>
#using "Sum.netmodule"
using namespace System;
public __gc class SumC
{
public:
    Sum __gc *t;
    SumC()
    {
        t = new Sum();          
    }
    int callCSharpSum(int a,int b)
    {
        return  t->add(a,b);
    }
};

===========================================

save it as sum.h

create sum.cpp file

============================================

#include <jni.h>
#include "test.h"
#include "sum.h"

JNIEXPORT jint JNICALL Java_test_add
    (JNIEnv *, jobject, jint a, jint b)
{
    SumC* t = new SumC();  
    return t->callCSharpSum(a ,b );
}

=============================================

optimize compiler to build /clr:oldSyntax
Include Jdk/Include directory path
build the project.
we will Get JSample DLL

run the project
with C#.net module,Native DLL file and class file at the same folder.

java test

25

but whenever i run the code with dll file and class file alone.
it shows bug report The crash happened outside the Java Virtual Machine in native code.
please clarify how to port managed code C# into C++ (Win32 Un-Managed code). library file.

  • 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. Editorial Team
    Editorial Team
    2026-05-27T22:37:09+00:00Added an answer on May 27, 2026 at 10:37 pm

    To use .NET assemblies from Java, I strongly suggest you look at IKVM, which is a Java VM that bridges to .NET Runtime.

    I’ve used this back in (I think) 2004 for production software and it worked nicely. The project is actively maintained and recieves support for .NET 4 and Java 7 these days.

    You have a choice of

    • running the Java code in IKVM so you can use .NET libraries
    • run a .NET program that loads java libraries (e.g. jars)

    Both ways, there is a preprocessing step to translate the jars to DLLS or viceversa.

    See http://ikvm.net

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

Sidebar

Related Questions

I'm getting a bug report that some functionality in some music-playing code in an
Running a Java Swing program on Ubuntu Linux, I'm getting an odd bug where
I'm getting a crash that, to me, seems as though it is a bug
I keep getting the following error message when I run my code in debug.
I am getting a bug when I use a text_area in my rails app.
I am developing a raid system and I am getting following BUG when I
I'm automating a web application (the Mantis bug tracker) and I'm getting an interesting
Getting the above error in following code. How to rectify it. Thanks. Please look
I am getting the following jvm crash every few days running Tomcat 6.0.16 on
I am trying to format a URL but am getting a bug out of

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.