visual j# not working in .net 4

2019-02-03 08:23发布

问题:

I tried to convert a project that relies on the vjs runtime to vs2010, but it errors out when trying to run.

It's giving the error that "Could not load file or assembly 'vjslib' or one of its dependencies. An attempt was made to load a program with an incorrect format."

I reinstalled the vjs runtime, but it didn't seem to help.

Is there any way to get get .net 4 to work with this?

回答1:

Very simple solution - Calling J# code from .NET 4.0

You take control and load it first supplying an explicit path. Then next time it's needed, it already knows the path (or it's already loaded in the AppDomain).

You will need to use LoadLibrary function, so import the pinvoke reference:

[DllImport("kernel32", SetLastError = true)]
static extern IntPtr LoadLibrary(string lpFileName);

The on load (either Main function in Console/WinForms or in Global.asax Application_Start):

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"));
}


回答2:

I have downloaded Microsoft Visual J# Version 2.0 Redistributable Package from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=4712 and installed it.The issue is resolved.



回答3:

I got this to work by copying C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vjsnativ.dll (for 64 bit Microsoft.NET\Framework64\v2.0.50727\vjsnativ.dll) to my application's debug/release directory.

I suspect Microsoft will need to release another j# redistributable package to work with .net 4.0. Meanwhile, this work-around does a fine job.



回答4:

The only way I could get it to work was to copy the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vjsnativ.dll to the C:\Windows\Microsoft.NET\Framework\v4.0.30319 folder. See http://community.microfocus.com/borland/managetrack/starteam/w/knowledge_base/17108.error-unable-to-load-dll-vjsnativ-the-specified-module-could-not-be-found-exception-from-hresult-0x8007007e.aspx



回答5:

To add to the existing answers, I found that the solutions didn't work for me.

First thing I did was to repair the Microsoft Visual J# 2.0 Redistributable Package -SE (x64) using Windows Control Panel (Just right click and click repair). This was in case I did any damage in my previous attempts to fix the problem.

I had already implemented the solution provided by David Thielen.

1 Extra step closed the deal for me (solved the problem): Copy "vjscor.dll", "vjslib.dll" and "vjsnativ.dll" from C:\Windows\Microsoft.NET\Framework64\v2.0.50727 To C:\Windows\Microsoft.NET\Framework\v2.0.50727

So basically the Microsoft package placed the correct dlls into the 64-bit .NET framework and I had to manually move them into the 32-bit folder which is then copy-pasted into my solution folder by David Thielen's solution (above).



标签: .net-4.0 j#