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

error BG0000: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. #1292

Open
tuyen-vuduc opened this issue Jan 11, 2025 · 7 comments
Labels
generator Issues binding a Java library (generator, class-parse, etc.) need-info Information has been requested from the original issue creator

Comments

@tuyen-vuduc
Copy link

Errror when creating binding library for io.ktor:ktor-utils-jvm:2.3.8

error BG0000: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
         at Mono.Collections.Generic.Collection`1.get_Item(Int32 index)
         at Java.Interop.Tools.JavaTypeSystem.ManagedApiImporter.ParseMethod(MethodDefinition method, JavaTypeModel declaringType, ApiImporterOptions options) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.JavaTypeSystem/Adap
      ters/ManagedApiImporter.cs:line 195
         at Java.Interop.Tools.JavaTypeSystem.ManagedApiImporter.ParseClass(TypeDefinition type, JavaTypeCollection collection, ApiImporterOptions options) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.JavaTypeSystem/Adapter
      s/ManagedApiImporter.cs:line 123
         at Java.Interop.Tools.JavaTypeSystem.ManagedApiImporter.ParseType(TypeDefinition type, JavaTypeCollection collection, ApiImporterOptions options) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.JavaTypeSystem/Adapters
      /ManagedApiImporter.cs:line 44
         at Java.Interop.Tools.JavaTypeSystem.ManagedApiImporter.Parse(AssemblyDefinition assembly, JavaTypeCollection collection, TypeDefinitionCache resolver, ApiImporterOptions options) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Int
      erop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs:line 22
         at generator.JavaTypeResolutionFixups.Fixup(String xmlFile, String outputXmlFile, DirectoryAssemblyResolver resolver, String[] references, TypeDefinitionCache cache, CodeGeneratorOptions opt) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/
      tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs:line 32
         at Xamarin.Android.Binder.CodeGenerator.Run(CodeGeneratorOptions options, DirectoryAssemblyResolver resolver) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/generator/CodeGenerator.cs:line 116
         at Xamarin.Android.Binder.CodeGenerator.Run(CodeGeneratorOptions options) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/generator/CodeGenerator.cs:line 50
         at Xamarin.Android.Binder.CodeGenerator.Main(String[] args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/generator/CodeGenerator.cs:line 33
@jpobst
Copy link
Contributor

jpobst commented Jan 13, 2025

Can you provide a minimal repro? I do not see this error with the following project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0-android</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <RootNamespace>issue_1292</RootNamespace>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <IsTrimmable>true</IsTrimmable>
  </PropertyGroup>
  
  <ItemGroup>
    <AndroidMavenLibrary Include="io.ktor:ktor-utils-jvm" Version="2.3.8" />
    <AndroidMavenLibrary Include="org.slf4j:slf4j-api" Version="1.7.36" />
    <AndroidMavenLibrary Include="io.ktor:ktor-io-jvm" Version="2.3.8" />
  </ItemGroup>
  
  <ItemGroup>
    <PackageReference Include="Xamarin.Kotlin.StdLib" Version="2.0.21.1" />
    <PackageReference Include="Xamarin.Kotlin.StdLib.Common" Version="2.0.21.1" />
    <PackageReference Include="Xamarin.Kotlin.StdLib.Jdk7" Version="2.0.21.1" />
    <PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="2.0.21.1" />
    <PackageReference Include="Xamarin.KotlinX.Coroutines.Android" Version="1.9.0.1" />
    <PackageReference Include="Xamarin.KotlinX.Coroutines.Core.Jvm" Version="1.9.0.1" />
    <PackageReference Include="Xamarin.KotlinX.Coroutines.Jdk8" Version="1.9.0.1" />
  </ItemGroup>
</Project>

@jpobst
Copy link
Contributor

jpobst commented Jan 13, 2025

Looking at the relevant code:

for (var i = 0; i < jni_signature.Parameters.Count; i++)
model.Parameters.Add (ParseParameterModel (model, jni_signature.Parameters [i], method.Parameters [i]));

This appears to be a case where:

  • We are trying to import a referenced Android binding .dll.
  • A method in that .dll has a [Register] signature that specifies that the method has N parameters, but the method actually has a different number of parameters.

Example: here (I) means the method takes a single int parameter, but the managed method actually takes no parameters.

[Register ("doThing", "(I)", "")]
public unsafe void DoThing () { ... }

@jpobst jpobst added need-info Information has been requested from the original issue creator generator Issues binding a Java library (generator, class-parse, etc.) labels Jan 13, 2025
@tuyen-vuduc
Copy link
Author

@jpobst Here is the binding source code.

BTW, I attempted to debug this source, but failed following the guidelines. Can you advise?

io.ktorktor-utils-jvm.2.3.8.zip

@jpobst
Copy link
Contributor

jpobst commented Jan 17, 2025

I get this error trying to build this project:

C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.145\tools\Xamarin.Android.Common.targets(893,3): error XACDJ7028: System.IO.FileNotFoundException: Could not find file 'C:\Users\jopobst\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.36\6c62681a2f655b49963a5983b8b0950a6120ae14\slf4j-api-1.7.36.jar'.
File name: 'C:\Users\jopobst\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.36\6c62681a2f655b49963a5983b8b0950a6120ae14\slf4j-api-1.7.36.jar'
   at System.IO.FileInfo.get_Length()
   at Xamarin.Android.Tasks.MonoAndroidHelper.SizeAndContentFileComparer.GetHashCode(FileInfo obj)
   at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value, Int32& location)
   at System.Collections.Generic.HashSet`1.Add(T item)
  ...

I'm not sure how this file is supposed to get to that path, though I do have a 1.7.30 version there.

@tuyen-vuduc
Copy link
Author

@jpobst Can you install Gradle and/or Android Studio? The other dependencies require gradle to download Android artifacts.

@tuyen-vuduc
Copy link
Author

@jpobst Have you been able to check it out? Any chances to guide me to debug on my machine?

@jpobst
Copy link
Contributor

jpobst commented Jan 21, 2025

@jpobst Can you install Gradle and/or Android Studio? The other dependencies require gradle to download Android artifacts.

I already have Android Studio on my machine, so it apparently requires something more than that.

Any chances to guide me to debug on my machine?

To debug locally, you would need to:

  • Clone this repository
  • Get Java.Interop.sln building on the command line
  • Open generator.slnf in VS
  • Get the failing command line from your failing build (likely using binlog)
  • Debug in VS using that startup command line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues binding a Java library (generator, class-parse, etc.) need-info Information has been requested from the original issue creator
Projects
None yet
Development

No branches or pull requests

2 participants