Re: Class.forName and csharp classes
Martin Gerhardy <[email protected]> Fri, 17 Feb 2017 19:20:24 +0000
| Newsgroups | gmane.comp.java.ikvm.devel |
|---|---|
| Message-ID | <0598D786697B0A42AAEE934493816053406A3B79@srv024038.bigpoint.local> |
--===============3486516838890178656== Content-Language: de-DE Content-Type: multipart/alternative; boundary="_000_0598D786697B0A42AAEE934493816053406A3B79srv024038bigpoi_" --_000_0598D786697B0A42AAEE934493816053406A3B79srv024038bigpoi_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hi Thanks for that offer - I put up a github repo at https://github.com/mgerha= rdy/ikvm-class-for-name Quick and dirty - also the compiled class files if disassembling them is ne= eded. There is a makefile included that shows the used commandlines that are/were= used to create the binaries. Again - thanks a lot for all your help Regards Martin ________________________________ Von: [email protected] [[email protected]] Gesendet: Freitag, 17. Februar 2017 18:55 An: Martin Gerhardy; Jeroen Frijters; [email protected] Betreff: RE: [Ikvm-developers] Class.forName and csharp classes Martin, Would you be willing to create and upload a test case for this into a Git R= epository? If you don=92t have a GitHub account I can create you a reposito= ry to use. I=92d like to get this into the set of Unit Tests. In order to d= o that it would be incredibly helpful for you to create a bare bones exampl= e that exhibits the behavior you are seeing. I also didn=92t see the versio= ns of tools you were using. That would be helpful as well. Feel free to contact me directly if you need help setting up the Test Case = for this. >From parts of my memory that could be completely fabricated I remember thei= r being issues in certain versions of .NET when one would attempt to load c= lasses from the Executing Domain that existed in the .exe assembly. I bet i= f you were to create a new Assembly, create a class in it, then add it to t= he path, everything would work. Also remember that the JDK after 7 (I belie= ve) has it=92s own pseudo Classloader domain-like management. So you might = need to use a different classloader when attempting to .forName your new cl= ass. Take a Java disassembler and see what your .NET CLR class is being turned i= nto as well. I hope to take a look at your sample test case and get this working for you= . If you have any issues getting it somewhere online let me know asap and I= =92ll help. Regards, Andrew {givenname}.{surname}@duelingcoders.com {givenname}.{surname}@gmail.com From: Martin Gerhardy<mailto:[email protected]> Sent: Friday, February 17, 2017 10:42 AM To: Jeroen Frijters<mailto:[email protected]>; [email protected]= forge.net<mailto:[email protected]> Subject: Re: [Ikvm-developers] Class.forName and csharp classes Hi Jeroen maybe I am misisng something, but the csharp class is part of the exe, the = dll (converted jar) is trying to load a class from the exe - do I have to a= dd the exe to the classloader in the csharp application? Isn't that implici= tly the case? Or do I have to create another dll for my csharp stuff and ju= st reference it from a minimal exe? Can you give an example on how to do that? Thanks again for helping me. Regards Martin ________________________________________ Von: Jeroen Frijters [[email protected]] Gesendet: Freitag, 17. Februar 2017 16:19 An: Martin Gerhardy; [email protected] Betreff: RE: Class.forName and csharp classes Hi Martin, In that case it is probably simply a class loader issue. The class loader y= ou use for Class.forName() must be able to see the assembly. The easiest so= lution is to add the assembly to the boot class loader with the ikvm.runtim= e.Startup.addBootClassPathAssembly() method. Regards, Jeroen > -----Original Message----- > From: Martin Gerhardy [mailto:[email protected]] > Sent: Friday, February 17, 2017 16:08 > To: Jeroen Frijters <[email protected]>; ikvm- > [email protected] > Subject: AW: Class.forName and csharp classes > > Hi Jeroen, > > thanks for the answer - I tried both: > > --------------------------- > using System.Diagnostics; > using System; > > [assembly: IKVM.Attributes.NoPackagePrefixAttribute] > namespace foo > { > class Foo > { > public Foo() > { > } > } > > class MainClass > { > public static void Main (string[] args) > { > Console.WriteLine("starting up..."); > Launcher.main("foo.Foo"); > } > } > } > --------------------------- > > > package foo; > > public class Launcher { > public static void main(final String name) { > try { > System.err.println("Starting up and trying to load = " + > name); > final Class<?> forName =3D Class.forName("cli." + n= ame); > System.out.println("Finished loading " + forName); > } catch (final ClassNotFoundException e) { > e.printStackTrace(); > } > } > } > > --------------------------- > > Neither works - neither the additional cli. namespace prefix nor adding > the attribute (Not sure if I did that one correctly) > > Compiling with the commands: > ikvmc -classloader:ikvm.runtime.ClassPathAssemblyClassLoader - > assemblyattributes:$(BIN)/AssemblyInfo.class -target:library $< > mcs -target:exe -main:foo.MainClass - > r:System.dll,IKVM.Runtime.dll,IKVM.OpenJDK.Core.dll,$(NAME).dll - > out:proof-of-concept.exe GuiceRepro.cs AssemblyInfo.cs > > > > Regards > Martin > > ________________________________________ > Von: Jeroen Frijters [[email protected]] > Gesendet: Freitag, 17. Februar 2017 14:50 > An: Martin Gerhardy; [email protected] > Betreff: RE: Class.forName and csharp classes > > Hi Martin, > > Did you take into account that the C# classes get a "cli." prefix in > Java (by default)? > > You can apply the IKVM.Attributes.NoPackagePrefixAttribute to the class > or assembly to disable this. > > Regards, > Jeroen > > > -----Original Message----- > > From: Martin Gerhardy [mailto:[email protected]] > > Sent: Wednesday, February 15, 2017 11:34 > > To: [email protected] > > Subject: [Ikvm-developers] Class.forName and csharp classes > > > > Hi, > > > > we are converting a deserialization jar via ikvm into a dll and bind a > > csharp class via guice to some of the serialized classes. The java > > code contains a call for Class.forName for that class. As our injected > > class is a csharp class, this doesn't work. Is there any way to work > > around this? (In the sense the Class.forName also finds csharp > > classes?) > > > > Regards > > Martin ---------------------------------------------------------------------------= --- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Ikvm-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ikvm-developers --_000_0598D786697B0A42AAEE934493816053406A3B79srv024038bigpoi_ Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable <html dir=3D"ltr"> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DWindows-1= 252"> <style>=0A= <!--=0A= @font-face=0A= {font-family:"Cambria Math"}=0A= @font-face=0A= {font-family:Calibri}=0A= p.MsoNormal, li.MsoNormal, div.MsoNormal=0A= {margin:0in;=0A= margin-bottom:.0001pt;=0A= font-size:11.0pt;=0A= font-family:"Calibri",sans-serif}=0A= a:link, span.MsoHyperlink=0A= {color:blue;=0A= text-decoration:underline}=0A= a:visited, span.MsoHyperlinkFollowed=0A= {color:#954F72;=0A= text-decoration:underline}=0A= @page WordSection1=0A= {margin:1.0in 1.0in 1.0in 1.0in}=0A= -->=0A= </style><style id=3D"owaParaStyle" type=3D"text/css">P {margin-top:0;margin= -bottom:0;}</style> </head> <body ocsi=3D"0" fpstyle=3D"1" lang=3D"EN-US" link=3D"blue" vlink=3D"#954F7= 2"> <div style=3D"direction: ltr;font-family: Tahoma;color: #000000;font-size: = 10pt;">Hi<br> <br> Thanks for that offer - I put up a github repo at <a href=3D"https://github= .com/mgerhardy/ikvm-class-for-name" target=3D"_blank"> https://github.com/mgerhardy/ikvm-class-for-name</a><br> <br> Quick and dirty - also the compiled class files if disassembling them is ne= eded.<br> <br> There is a makefile included that shows the used commandlines that are/were= used to create the binaries.<br> <br> Again - thanks a lot for all your help<br> <br> Regards<br> Martin<br> <br> <div style=3D"font-family: Times New Roman; color: #000000; font-size: 16px= "> <hr tabindex=3D"-1"> <div style=3D"direction: ltr;" id=3D"divRpF191629"><font color=3D"#000000" = face=3D"Tahoma" size=3D"2"><b>Von:</b> [email protected] [andrew.fin= [email protected]]<br> <b>Gesendet:</b> Freitag, 17. Februar 2017 18:55<br> <b>An:</b> Martin Gerhardy; Jeroen Frijters; [email protected]= rge.net<br> <b>Betreff:</b> RE: [Ikvm-developers] Class.forName and csharp classes<br> </font><br> </div> <div></div> <div> <div class=3D"WordSection1"> <p class=3D"MsoNormal">Martin,</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Would you be willing to create and upload a test cas= e for this into a Git Repository? If you don=92t have a GitHub account I ca= n create you a repository to use. I=92d like to get this into the set of Un= it Tests. In order to do that it would be incredibly helpful for you to create a bare bones example that exhibits= the behavior you are seeing. I also didn=92t see the versions of tools you= were using. That would be helpful as well.</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Feel free to contact me directly if you need help se= tting up the Test Case for this.</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">From parts of my memory that could be completely fab= ricated I remember their being issues in certain versions of .NET when one = would attempt to load classes from the Executing Domain that existed in the= .exe assembly. I bet if you were to create a new Assembly, create a class in it, then add it to the path, e= verything would work. Also remember that the JDK after 7 (I believe) has it= =92s own pseudo Classloader domain-like management. So you might need to us= e a different classloader when attempting to .forName your new class. </p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Take a Java disassembler and see what your .NET CLR = class is being turned into as well.</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">I hope to take a look at your sample test case and g= et this working for you. If you have any issues getting it somewhere online= let me know asap and I=92ll help.</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Regards,</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Andrew</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">{givenname}.{surname}@duelingcoders.com</p> <p class=3D"MsoNormal">{givenname}.{surname}@gmail.com</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal"> </p> <div style=3D"border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0i= n 0in 0in"> <p class=3D"MsoNormal" style=3D"border:none; padding:0in"><b>From: </b><a h= ref=3D"mailto:[email protected]" target=3D"_blank">Martin Gerhardy</a= ><br> <b>Sent: </b>Friday, February 17, 2017 10:42 AM<br> <b>To: </b><a href=3D"mailto:[email protected]" target=3D"_blank">Jeroen Fr= ijters</a>; <a href=3D"mailto:[email protected]" target=3D"_blank">= [email protected]</a><br> <b>Subject: </b>Re: [Ikvm-developers] Class.forName and csharp classes</p> </div> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Hi Jeroen</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">maybe I am misisng something, but the csharp class i= s part of the exe, the dll (converted jar) is trying to load a class from t= he exe - do I have to add the exe to the classloader in the csharp applicat= ion? Isn't that implicitly the case? Or do I have to create another dll for my csharp stuff and just reference = it from a minimal exe?</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Can you give an example on how to do that? Thanks ag= ain for helping me.</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Regards</p> <p class=3D"MsoNormal">Martin</p> <p class=3D"MsoNormal">________________________________________</p> <p class=3D"MsoNormal">Von: Jeroen Frijters [[email protected]]</p> <p class=3D"MsoNormal">Gesendet: Freitag, 17. Februar 2017 16:19</p> <p class=3D"MsoNormal">An: Martin Gerhardy; [email protected]= ge.net</p> <p class=3D"MsoNormal">Betreff: RE: Class.forName and csharp classes</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Hi Martin,</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">In that case it is probably simply a class loader is= sue. The class loader you use for Class.forName() must be able to see the a= ssembly. The easiest solution is to add the assembly to the boot class load= er with the ikvm.runtime.Startup.addBootClassPathAssembly() method.</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">Regards,</p> <p class=3D"MsoNormal">Jeroen</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">> -----Original Message-----</p> <p class=3D"MsoNormal">> From: Martin Gerhardy [mailto:M.Gerhardy@bigpoi= nt.net]</p> <p class=3D"MsoNormal">> Sent: Friday, February 17, 2017 16:08</p> <p class=3D"MsoNormal">> To: Jeroen Frijters <[email protected]>; = ikvm-</p> <p class=3D"MsoNormal">> [email protected]</p> <p class=3D"MsoNormal">> Subject: AW: Class.forName and csharp classes</= p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> Hi Jeroen,</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> thanks for the answer - I tried both:</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> ---------------------------</p> <p class=3D"MsoNormal">> using System.Diagnostics;</p> <p class=3D"MsoNormal">> using System;</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> [assembly: IKVM.Attributes.NoPackagePrefixAttri= bute]</p> <p class=3D"MsoNormal">> namespace foo</p> <p class=3D"MsoNormal">> {</p> <p class=3D"MsoNormal">> class Foo</= p> <p class=3D"MsoNormal">> {</p> <p class=3D"MsoNormal">> = public Foo()</p> <p class=3D"MsoNormal">> = {</p> <p class=3D"MsoNormal">> = }</p> <p class=3D"MsoNormal">> }</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> class MainC= lass</p> <p class=3D"MsoNormal">> {</p> <p class=3D"MsoNormal">> = public static void Main (string[] args= )</p> <p class=3D"MsoNormal">> = {</p> <p class=3D"MsoNormal">> = &nb= sp; Console.WriteLine("starting up...");</p> <p class=3D"MsoNormal">> = &nb= sp; Launcher.main("foo.Foo");</p> <p class=3D"MsoNormal">> = }</p> <p class=3D"MsoNormal">> }</p> <p class=3D"MsoNormal">> }</p> <p class=3D"MsoNormal">> ---------------------------</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> package foo;</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> public class Launcher {</p> <p class=3D"MsoNormal">> public stat= ic void main(final String name) {</p> <p class=3D"MsoNormal">> = try {</p> <p class=3D"MsoNormal">> = &nb= sp; System.err.println("Starting up and trying to load " &#= 43;</p> <p class=3D"MsoNormal">> name);</p> <p class=3D"MsoNormal">> = &nb= sp; final Class<?> forName =3D Class.forName("cli." &= #43; name);</p> <p class=3D"MsoNormal">> = &nb= sp; System.out.println("Finished loading " + forName);<= /p> <p class=3D"MsoNormal">> = } catch (final ClassNotFoundException = e) {</p> <p class=3D"MsoNormal">> = &nb= sp; e.printStackTrace();</p> <p class=3D"MsoNormal">> = }</p> <p class=3D"MsoNormal">> }</p> <p class=3D"MsoNormal">> }</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> ---------------------------</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> Neither works - neither the additional cli. nam= espace prefix nor adding</p> <p class=3D"MsoNormal">> the attribute (Not sure if I did that one corre= ctly)</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> Compiling with the commands:</p> <p class=3D"MsoNormal">> ikvmc -clas= sloader:ikvm.runtime.ClassPathAssemblyClassLoader -</p> <p class=3D"MsoNormal">> assemblyattributes:$(BIN)/AssemblyInfo.class -t= arget:library $<</p> <p class=3D"MsoNormal">> mcs -target= :exe -main:foo.MainClass -</p> <p class=3D"MsoNormal">> r:System.dll,IKVM.Runtime.dll,IKVM.OpenJDK.Core= .dll,$(NAME).dll -</p> <p class=3D"MsoNormal">> out:proof-of-concept.exe GuiceRepro.cs Assembly= Info.cs</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> Regards</p> <p class=3D"MsoNormal">> Martin</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> ________________________________________</p> <p class=3D"MsoNormal">> Von: Jeroen Frijters [[email protected]]</p> <p class=3D"MsoNormal">> Gesendet: Freitag, 17. Februar 2017 14:50</p> <p class=3D"MsoNormal">> An: Martin Gerhardy; [email protected]= ceforge.net</p> <p class=3D"MsoNormal">> Betreff: RE: Class.forName and csharp classes</= p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> Hi Martin,</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> Did you take into account that the C# classes g= et a "cli." prefix in</p> <p class=3D"MsoNormal">> Java (by default)?</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> You can apply the IKVM.Attributes.NoPackagePref= ixAttribute to the class</p> <p class=3D"MsoNormal">> or assembly to disable this.</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> Regards,</p> <p class=3D"MsoNormal">> Jeroen</p> <p class=3D"MsoNormal">> </p> <p class=3D"MsoNormal">> > -----Original Message-----</p> <p class=3D"MsoNormal">> > From: Martin Gerhardy [mailto:M.Gerhardy@b= igpoint.net]</p> <p class=3D"MsoNormal">> > Sent: Wednesday, February 15, 2017 11:34</= p> <p class=3D"MsoNormal">> > To: [email protected]<= /p> <p class=3D"MsoNormal">> > Subject: [Ikvm-developers] Class.forName a= nd csharp classes</p> <p class=3D"MsoNormal">> ></p> <p class=3D"MsoNormal">> > Hi,</p> <p class=3D"MsoNormal">> ></p> <p class=3D"MsoNormal">> > we are converting a deserialization jar vi= a ikvm into a dll and bind a</p> <p class=3D"MsoNormal">> > csharp class via guice to some of the seri= alized classes. The java</p> <p class=3D"MsoNormal">> > code contains a call for Class.forName for= that class. As our injected</p> <p class=3D"MsoNormal">> > class is a csharp class, this doesn't work= . Is there any way to work</p> <p class=3D"MsoNormal">> > around this? (In the sense the Class.forNa= me also finds csharp</p> <p class=3D"MsoNormal">> > classes?)</p> <p class=3D"MsoNormal">> ></p> <p class=3D"MsoNormal">> > Regards</p> <p class=3D"MsoNormal">> > Martin</p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal"> </p> <p class=3D"MsoNormal">----------------------------------------------------= --------------------------</p> <p class=3D"MsoNormal">Check out the vibrant tech community on one of the w= orld's most</p> <p class=3D"MsoNormal">engaging tech sites, SlashDot.org! http://sdm.link/s= lashdot</p> <p class=3D"MsoNormal">_______________________________________________</p> <p class=3D"MsoNormal">Ikvm-developers mailing list</p> <p class=3D"MsoNormal">[email protected]</p> <p class=3D"MsoNormal">https://lists.sourceforge.net/lists/listinfo/ikvm-de= velopers</p> <p class=3D"MsoNormal"> </p> </div> </div> </div> </div> </body> </html> --_000_0598D786697B0A42AAEE934493816053406A3B79srv024038bigpoi_-- --===============3486516838890178656== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot --===============3486516838890178656== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Ikvm-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ikvm-developers --===============3486516838890178656==--