Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing ikvm.home with User setting before initialization #580

Open
except11 opened this issue Aug 22, 2024 · 3 comments
Open

Customizing ikvm.home with User setting before initialization #580

except11 opened this issue Aug 22, 2024 · 3 comments

Comments

@except11
Copy link

Hi, I was trying to use User settings to override ikvm.home.root since I saw in code IKVM checking it first

I am doing it like this
IKVM.Runtime.JVM.Properties.User.Add("ikvm.home.root", "ikvm-root");

But to do it system tries to construct static objects and tries to get home path before I can set it

System.TypeInitializationException: The type initializer for 'Internal' threw an exception.
---> IKVM.Runtime.InternalException: Could not locate ikvm home path.
at IKVM.Runtime.JVM.Properties.GetHomePath()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at IKVM.Runtime.JVM.Internal..cctor()
--- End of inner exception stack trace ---
at IKVM.Runtime.JVM.Init()
at IKVM.Runtime.RuntimeInit.Init()
at .cctor()

I managed to solve my problem by adding PrivateAssets="buildTransitive" to reference and copying bunch of assets myself, since I can't just replace ikvm.properties - its added to build forcefully, and I want my own version.

Maybe add ikvm.user.properties for this purpose or something? Currently it looks you can customize the path in different ways but none of them actually work as is

@except11 except11 changed the title Adding User setting before initialization Customizing ikvm.home with User setting before initialization Aug 22, 2024
@wasabii
Copy link
Contributor

wasabii commented Aug 22, 2024

You can just use the build script to lay down your own ikvm.properties. But yeah, we can't do any code-based dynamic lookup of this because module inits happen before everything. On Framework, app.config works since it's loaded by the framework. We could find a similar thing for Core.

@wasabii
Copy link
Contributor

wasabii commented Aug 22, 2024

Replacing ikvm.properties shouldn't be that hard though. You should probably just be able to override the target that lays it down.

@except11
Copy link
Author

except11 commented Aug 26, 2024

Yes, I did it like this
<Target Name="ReplaceIkvmProperties" AfterTargets="GetDefaultIkvmPropertiesFile"> <ItemGroup> <None Remove="@(None)" Condition="'%(Extension)'=='.properties'" /> <Content Remove="@(Content)" Condition="'%(Extension)'=='.properties'" /> <None Include="ikvm.properties"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> <Message Text="Replaced ikvm.properties @(None)" Importance="high" /> </Target>

And its working while building, but I want to keep java stuff in a separate project and I reference it from bunch of other projects, and when I publish main project I still get Found multiple publish output files with the same relative path. So I had to also specify PrivateAssets="buildTransitive" in IKVM reference since I don't want to change main project's csproj file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants