ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.28k stars 121 forks source link

error MSB4057: "The target "ResolveIkvmRuntimeAssembly" does not exist in the project." on .NET Framework 4.6.2 #467

Closed NightOwl888 closed 10 months ago

NightOwl888 commented 10 months ago

Here is a minimal example of the issue. I am compiling on Windows 10 x64 using Visual Studio 17.5.5.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net6.0;net462</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="IKVM" Version="8.7.3" />
    <PackageReference Include="IKVM.Maven.Sdk" Version="1.6.7" />
  </ItemGroup>

  <ItemGroup>
    <MavenReference Include="org.apache.opennlp:opennlp-tools" Version="1.9.4" />
  </ItemGroup>

</Project>

I saw #230, and tried to run dotnet msbuild /restore, but I get the same error on the command line.

Microsoft Windows [Version 10.0.19045.3324]
(c) Microsoft Corporation. All rights reserved.

F:\Users\shad\source\repos\ExampleIkvmNetFrameworkError\ExampleIkvmNetFrameworkError>dotnet msbuild /restore
MSBuild version 17.5.1+f6fdcf537 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.targets(89,54): error MSB4057: The target "ResolveI
kvmRuntimeAssembly" does not exist in the project. [F:\Users\shad\source\repos\ExampleIkvmNetFrameworkError\Examp
leIkvmNetFrameworkError\ExampleIkvmNetFrameworkError.csproj::TargetFramework=net462]
  ExampleIkvmNetFrameworkError -> F:\Users\shad\source\repos\ExampleIkvmNetFrameworkError\ExampleIkvmNetFramework
  Error\bin\Debug\net6.0\ExampleIkvmNetFrameworkError.dll

F:\Users\shad\source\repos\ExampleIkvmNetFrameworkError\ExampleIkvmNetFrameworkError>

This issue doesn't happen when I remove net462 from the project and only target net6.0. I haven't yet checked to see what the latest version of IKVM is that this worked in, but I am going to do that now since there doesn't seem to be any version that works everywhere at once so I will have to select version of IKVM based on TFM. I do know that it doesn't function on 8.7.1 or higher.

wasabii commented 10 months ago

The lowest supported version of Framework is 4.7.2 for IKVM 8.7+.

NightOwl888 commented 10 months ago

Gotcha. That seems to be the issue.

Now, if only it didn't throw that TypeInitializationExeption... (#462)

wasabii commented 10 months ago

Gotcha. That seems to be the issue.

Now, if only it didn't throw that TypeInitializationExeption... (#462)

Can you give 8.7.4-pre.16 a go?

NightOwl888 commented 10 months ago

Gotcha. That seems to be the issue. Now, if only it didn't throw that TypeInitializationExeption... (#462)

Can you give 8.7.4-pre.16 a go?

Still has the issue...

    System.TypeInitializationException : The type initializer for '<Module>' threw an exception.
  ----> System.TypeInitializationException : The type initializer for 'java.io.FileInputStream' threw an exception.
  ----> System.TypeInitializationException : The type initializer for 'IKVM.Runtime.LibJava' threw an exception.
  ----> System.TypeInitializationException : The type initializer for 'IKVM.Runtime.LibJvm' threw an exception.
  ----> IKVM.Runtime.InternalException : Could not load libjvm.

Putting java.lang.Object foo = new java.lang.Object(); before the operation doesn't fix the issue, either.

wasabii commented 10 months ago

Well, I'm not getting that anymore. Again, any chance of a repro?

NightOwl888 commented 10 months ago

Here you go.

https://github.com/NightOwl888/ExampleIkvmInitializationError

Only 3 lines of code. But since it has to load a binary file it was easier to embed it.

wasabii commented 10 months ago

ExampleIkvmInitializationError was named wrong.

After I fixed that it worked fine.

NightOwl888 commented 10 months ago

Hmm...I still get the error after fixing it. I just pushed a commit.

wasabii commented 10 months ago

Can you try cleaning out your bin and obj dir?

NightOwl888 commented 10 months ago

Well, that did the trick.

image

Still having an issue with getting a project that depends on the test project to compile, though.

18>------ Build started: Project: Lucene.Net.Tests.AllProjects, Configuration: Debug Any CPU ------
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning : warning IKVMC0100: Class "org.osgi.framework.BundleActivator" not found
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning : *** INTERNAL COMPILER ERROR ***
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning : PLEASE FILE A BUG REPORT FOR IKVM.NET WHEN YOU SEE THIS MESSAGE
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning : IKVM.Tools.Importer, Version=8.7.3.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning : C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning : 4.0.30319.42000 64-bit
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning : System.NullReferenceException: Object reference not set to an instance of an object.
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Runtime.AttributeHelper.GetEditorBrowsableNever() in /_/src/IKVM.Runtime/AttributeHelper.cs:line 402
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Runtime.RuntimeByteCodeJavaType.JavaTypeImpl.LinkMethod(RuntimeJavaMethod mw) in /_/src/IKVM.Runtime/RuntimeByteCodeJavaType.JavaTypeImpl.cs:line 2487
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Runtime.RuntimeJavaMethod.DoLinkMethod() in /_/src/IKVM.Runtime/RuntimeJavaMethod.cs:line 339
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Runtime.RuntimeJavaMethod.Link(LoadMode mode) in /_/src/IKVM.Runtime/RuntimeJavaMethod.cs:line 329
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Runtime.RuntimeByteCodeJavaType.JavaTypeImpl.Finish() in /_/src/IKVM.Runtime/RuntimeByteCodeJavaType.JavaTypeImpl.cs:line 1187
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Tools.Importer.RuntimeImportByteCodeJavaType.Finish() in /_/src/IKVM.Tools.Importer/RuntimeImportByteCodeJavaType.cs:line 116
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Runtime.DynamicClassLoader.FinishAll() in /_/src/IKVM.Runtime/DynamicClassLoader.cs:line 412
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Tools.Importer.CompilerClassLoader.Compile(RuntimeContext context, StaticCompiler compiler, String runtimeAssembly, List`1 optionsList) in /_/src/IKVM.Tools.Importer/CompilerClassLoader.cs:line 2547
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Tools.Importer.IkvmImporterInternal.Compile(String[] args) in /_/src/IKVM.Tools.Importer/IkvmImporterInternal.cs:line 196
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): warning :    at IKVM.Tools.Importer.IkvmImporterInternal.Execute(String[] args) in /_/src/IKVM.Tools.Importer/IkvmImporterInternal.cs:line 111
18>F:\Users\shad\.nuget\packages\ikvm\8.7.3\buildTransitive\IKVM.Tasks.targets(31,9): error MSB4181: The "IkvmCompiler" task returned false but did not log an error.
18>Done building project "Lucene.Net.Tests.AllProjects.csproj" -- FAILED.
========== Build: 17 succeeded, 1 failed, 9 up-to-date, 0 skipped ==========
========== Build started at 3:32 AM and took 42.727 seconds ==========

What is weird is that I can compile the project that depends on MavenReference fine. I can compile the test project that depends on that fine (neither even generate a warning). But when I go up another level, I get this failure. Just posting this in case you have any ideas - I still need to go through to make sure something isn't amiss with the configuration.

wasabii commented 10 months ago

This looks like a new one. Needs a new issue.

NightOwl888 commented 10 months ago

It took several hours to find the problem, but it boils down to the test project (which depends directly on the project that reference IKVM) had this in it:

  <ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
    <Reference Include="System"/>
  </ItemGroup>

So, this was causing a conflict with the references that are provided by IKVM, causing an error. These have been in the project since its early days (and have been copied to new test projects as they are created) and we have since added this at the solution level Directory.Build.targets:

  <!-- Global PackageReferences -->
  <ItemGroup>
    <!-- This is to allow the .NET Framework references to be machine-indepenedent so builds can happen without installing prerequisites -->
    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="$(MicrosoftNETFrameworkReferenceAssembliesPackageReferenceVersion)" PrivateAssets="All" />
  </ItemGroup>

But including a reference to System in both ways didn't generate a warning or error of any kind before. With IKVM it just errors out and doesn't give any indication as to why. I am not sure this can be characterized as a bug, but it seems like better error reporting is needed here.