求救:
我在C#里呼叫java包,
參考到:
IKVM.OpenJDK.Core.dll
IKVM.Runtime.dll
IKVM.Runtime.JNI.dll
還有一個打包好的java包:WsRequestDemo.dll
但是在使用時跳出錯誤:“java.lang.StdIO”的型別初始值設定項引發例外
具體為:
未處理 System.TypeInitializationException
Message="“java.lang.StdIO”的型別初始值設定項引發例外。"
Source="IKVM.OpenJDK.Core"
TypeName="java.lang.StdIO"
StackTrace:
在 java.lang.System.get_out()
在 java.lang.Class$3.run()
在 java.lang.Class$3.run()
在 java.security.AccessController.doPrivileged(Object , AccessControlContext , CallerID )
在 java.security.AccessController.doPrivileged(PrivilegedAction action, CallerID )
在 java.lang.Class.checkInitted()
在 java.lang.Class.privateGetDeclaredConstructors(Boolean )
在 java.lang.Class.getConstructor0(Class[] , Int32 )
在 java.lang.Class.newInstance0(CallerID )
在 java.lang.Class.newInstance(CallerID )
在 sun.security.jca.ProviderConfig$2.run()
在 sun.security.jca.ProviderConfig$2.run()
在 java.security.AccessController.doPrivileged(Object , AccessControlContext , CallerID )
在 java.security.AccessController.doPrivileged(PrivilegedAction action, CallerID )
在 sun.security.jca.ProviderConfig.doLoadProvider()
在 sun.security.jca.ProviderConfig.getProvider()
在 sun.security.jca.ProviderList.getProvider(Int32 )
在 sun.security.jca.ProviderList.getService(String type, String name)
在 sun.security.jca.GetInstance.getInstance(String type, Class clazz, String algorithm)
在 java.security.Security.getImpl(String , String , String )
在 java.security.MessageDigest.getInstance(String algorithm)
在 com.zht.WsRequestDemo.getMessageDigest(String str1, String str2)
在 WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) 位置 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:行號 28
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 WindowsFormsApplication1.Program.Main() 位置 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\projects\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:行號 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: System.IO.FileNotFoundException
Message="未能加載檔案或程式集“IKVM.OpenJDK.Util, Version=7.2.4630.5, Culture=neutral, PublicKeyToken=13235d27fcbfff58”或它的某一個依賴項。系統找不到指定的檔案。"
Source="IKVM.OpenJDK.Core"
FileName="IKVM.OpenJDK.Util, Version=7.2.4630.5, Culture=neutral, PublicKeyToken=13235d27fcbfff58"
FusionLog="=== 預系結狀態資訊 ===\r\n日志: 用戶 = VSTFS\\Administrator\r\n日志: DisplayName = IKVM.OpenJDK.Util, Version=7.2.4630.5, Culture=neutral, PublicKeyToken=13235d27fcbfff58\n (Fully-specified)\r\n日志: Appbase = file:///C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/projects/WindowsFormsApplication1/WindowsFormsApplication1/bin/Debug/\r\n日志: 初始 PrivatePath = NULL\r\n呼叫程式集: IKVM.OpenJDK.Core, Version=7.2.4630.5, Culture=neutral, PublicKeyToken=13235d27fcbfff58。\r\n===\r\n日志: 此系結從 default 加載背景關系開始。\r\n日志: 未找到應用程式組態檔。\r\n日志: 使用 C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\config\\machine.config 的計算機組態檔。\r\n日志: 策略后參考: IKVM.OpenJDK.Util, Version=7.2.4630.5, Culture=neutral, PublicKeyToken=13235d27fcbfff58\r\n日志: 相同的系結已出現過,因 hr = 0x80070002 而失敗。\r\n"
StackTrace:
在 sun.misc.URLClassPath.JarLoader.ensureOpen()
在 sun.misc.URLClassPath.JarLoader..ctor(URL , URLStreamHandler , HashMap )
在 sun.misc.URLClassPath$3.run()
在 sun.misc.URLClassPath$3.run()
在 java.security.AccessController.doPrivileged(Object , AccessControlContext , CallerID )
在 java.security.AccessController.doPrivileged(PrivilegedExceptionAction action, CallerID )
在 sun.misc.URLClassPath.getLoader(URL )
在 sun.misc.URLClassPath.getLoader(Int32 )
在 sun.misc.URLClassPath.access$000(URLClassPath , Int32 )
在 sun.misc.URLClassPath$1.next()
在 sun.misc.URLClassPath$1.hasMoreElements()
在 IKVM.Internal.AssemblyClassLoader.<GetResourcesImpl>d__0.MoveNext()
在 IKVM.Internal.AssemblyClassLoader.<GetResourcesImpl>d__0.MoveNext()
在 IKVM.NativeCode.ikvm.runtime.AssemblyClassLoader.getResources(ClassLoader classLoader, Assembly assembly, String name)
在 ikvm.runtime.AssemblyClassLoader.getResources(ClassLoader , Assembly , String )
在 ikvm.runtime.AssemblyClassLoader.getResources(String name)
在 java.util.ServiceLoader.LazyIterator.hasNext()
在 java.util.ServiceLoader$1.hasNext()
在 java.nio.charset.Charset$1.getNext()
在 java.nio.charset.Charset$1.hasNext()
在 java.nio.charset.Charset$2.run()
在 java.nio.charset.Charset$2.run()
在 java.security.AccessController.doPrivileged(Object , AccessControlContext , CallerID )
在 java.security.AccessController.doPrivileged(PrivilegedAction action, CallerID )
在 java.nio.charset.Charset.lookupViaProviders(String )
在 java.nio.charset.Charset.lookup2(String )
在 java.nio.charset.Charset.lookup(String )
在 java.nio.charset.Charset.defaultCharset()
在 sun.nio.cs.StreamEncoder.forOutputStreamWriter(OutputStream out, Object lock, String charsetName)
在 java.io.OutputStreamWriter..ctor(OutputStream out)
在 java.io.PrintStream..ctor(Boolean , OutputStream )
在 java.io.PrintStream..ctor(OutputStream out, Boolean autoFlush)
在 java.lang.StdIO..cctor()
InnerException:
uj5u.com熱心網友回復:
我也碰到了該問題,不知道如何解決uj5u.com熱心網友回復:
樓主怎么解決的?可以告知下嗎?我這邊AES(SHA1PRNG)加密的時候報了這個錯誤uj5u.com熱心網友回復:
還真么有這么操作過。推薦你用web介面吧。uj5u.com熱心網友回復:
要參考IKVM安裝檔案夾下的檔案:%IKVM_HOME%\bin\IKVM.OpenJDK.Core.dll
%IKVM_HOME%\bin\IKVM.Runtime.dll
%IKVM_HOME%\bin\IKVM.Runtime.JNI.dll
參考后編譯整個工程, 這樣會在.Net專案的bin檔案夾中生成以下dll檔案:
IKVM.AWT.WinForms.dll
IKVM.OpenJDK.Beans.dll
IKVM.OpenJDK.Charsets.dll
IKVM.OpenJDK.Corba.dll
IKVM.OpenJDK.Core.dll
IKVM.OpenJDK.Management.dll
IKVM.OpenJDK.Media.dll
IKVM.OpenJDK.Misc.dll
IKVM.OpenJDK.Naming.dll
IKVM.OpenJDK.Remoting.dll
IKVM.OpenJDK.Security.dll
IKVM.OpenJDK.SwingAWT.dll
IKVM.OpenJDK.Text.dll
IKVM.OpenJDK.Util.dll
IKVM.OpenJDK.XML.API.dll
IKVM.Runtime.dll
IKVM.Runtime.JNI.dll
把這些檔案拷到專案里面單獨的一個新建的commonLib檔案夾中,
再洗掉原來參考的%IKVM_HOME%\bin\那三個參考,
再添加commonLib檔案夾中所有的dll
重新編譯生成, 應該就可以了.
uj5u.com熱心網友回復:
將KIVMbin中的 dll 全部拷貝到C#專案的debug中就可以了轉載請註明出處,本文鏈接:https://www.uj5u.com/net/19501.html
標籤:C#
