ikvm icon indicating copy to clipboard operation
ikvm copied to clipboard

Are you support SelfContained=true && PublishSingleFile=true?

Open google-mirror opened this issue 1 year ago • 4 comments

Throw Exception when SelfContained=true && PublishSingleFile=true since 'typeof(JVM).Assembly.Location' will get null

https://github.com/ikvmnet/ikvm/blob/1404d8467c509fe6074ac0e7a030323028b7706c/src/IKVM.Runtime/JVM.Properties.cs#L82

error IL3000: 'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'

google-mirror avatar Mar 19 '24 05:03 google-mirror

Haven't tried it since Core 3. Seems broken. Need to research changes made to single file.

Core 3 extracted files before running them, which is why this used to work.

wasabii avatar Mar 19 '24 22:03 wasabii

Since .NET 5 AppContext.BaseDirectory always returns actual .exe's directory in regular, single file and AOT scenarios. So I think it's safe to change home path detection to use this property instead, but we may introduce a behaviour change where ikvm would start always looking into exe's directory and not where the IKVM dll is located by itself. Maybe the better solution would be checking if Assembly.Location is null or empty, then fall back to AppContext.BaseDirectory.

zznty avatar Mar 26 '24 02:03 zznty

This is happening to me on latest stable nuget (8.4.6 I think?). (Edit: 8.7.6) Adding the full error here for anyone searching on Google:

System.TypeInitializationException: The type initializer for 'java.lang.System' threw an exception.
 ---> System.TypeInitializationException: the type initializer for '<Module>' threw an exception.
 ---> System.TypeInitializationException: the type initializer for 'Internal' threw an exception.
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String path1, String path2)
   at IKVM.Runtime.JVM.Properties.GetHomePath()
<etc>

I would suggest a check to see if the rootPath variable in GetHomePath is null or empty. If so, fall back to AppContext.BaseDirectory.

The-MAZZTer avatar Apr 16 '24 22:04 The-MAZZTer

This should be resolved on 8.9 when it is released, as the changes were made to develop.

wasabii avatar May 31 '24 16:05 wasabii

Check 8.9.0-pre.1.

wasabii avatar Jul 06 '24 23:07 wasabii