Skip to content

Commit 8b36274

Browse files
committed
[jnimarshalmethod-gen] Support resolving types from active assembly
For reasons I'm not going to investigate, if an interface type is defined in the assembly that `jnimarshalmethod-gen` is processing, `Assembly.Location` will be the empty string, which causes an error: % dotnet bin/Release-net8.0/jnimarshalmethod-gen.dll bin/TestRelease-net8.0/Java.Base-Tests.dll -v -v --keeptemp … error JM4006: jnimarshalmethod-gen: Unable to process assembly 'bin/TestRelease-net8.0/Java.Base-Tests.dll' Name can not be empty System.ArgumentException: Name can not be empty at Mono.Cecil.AssemblyNameReference.Parse(String fullName) at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName, ReaderParameters parameters) in /Users/runner/work/1/s/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 261 at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName) in /Users/runner/work/1/s/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 256 at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.GetAssembly(String fileName) in /Users/runner/work/1/s/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 251 at Xamarin.Android.Tools.JniMarshalMethodGenerator.Extensions.NeedsMarshalMethod(MethodDefinition md, DirectoryAssemblyResolver resolver, TypeDefinitionCache cache, MethodInfo method, String& name, String& methodName, String& signature) in /Users/runner/work/1/s/tools/jnimarshalmethod-gen/App.cs:line 790 at Xamarin.Android.Tools.JniMarshalMethodGenerator.App.CreateMarshalMethodAssembly(String path) in /Users/runner/work/1/s/tools/jnimarshalmethod-gen/App.cs:line 538 at Xamarin.Android.Tools.JniMarshalMethodGenerator.App.ProcessAssemblies(List`1 assemblies) in /Users/runner/work/1/s/tools/jnimarshalmethod-gen/App.cs:line 285 Update `App.NeedsMarshalMethod()` so that when the assembly Location is not present, `DirectoryAssemblyResolver.Resolve(assemblyName)` is instead used. This prevents the `ArgumentException`.
1 parent 850b06d commit 8b36274

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

build-tools/Java.Interop.Sdk/Sdk/Sdk.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
</XmlPeek>
161161
<PropertyGroup>
162162
<DefineConstants>$(DefineConstants);$([System.String]::Copy('$(_GeneratedDefineConstants)').Replace ('%24(DefineConstants);', ''))</DefineConstants>
163-
</PropertyGroup>
163+
</PropertyGroup>
164164
</Target>
165165

166166
<Target Name="_CleanupManagedBinding" />

tools/jnimarshalmethod-gen/App.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,12 @@ public static bool NeedsMarshalMethod (this MethodDefinition md, DirectoryAssemb
786786
if (iface.IsGenericType)
787787
continue;
788788

789+
var location = iface.Assembly.Location;
790+
var ad = string.IsNullOrEmpty (location)
791+
? resolver.Resolve (iface.Assembly.GetName ().Name)
792+
: resolver.GetAssembly (location);
793+
789794
var ifaceMap = method.DeclaringType.GetInterfaceMap (iface);
790-
var ad = resolver.GetAssembly (iface.Assembly.Location);
791795
var id = ad.MainModule.GetType (iface.GetCecilName ());
792796

793797
if (id == null) {

0 commit comments

Comments
 (0)