Search Issue Tracker

Fixed in 2019.3

Votes

2

Found in

2018.3.0a1

2018.3.11f1

2019.1.0a1

2019.2.0a1

Issue ID

1143057

Regression

No

Script compilation pipeline doesn't warn if asmdef is named the same as a native plugin in the project, causing mayhem

Scripting

-

Steps to reproduce:
1. Download "case 1143057.zip"
2. Zip will contain two projects one with Custom Package with .dll (TestDLL - KO) another project has the same package moved to asset folder (TestDLL - OK)
3. Open "TestDLL - KO" project
4. Switch platform to UWP and build project

Results: Build fails with a custom package. The build is successful when the custom package is move to Assets folder.

Reproduced with: 2019.2.0a11, 2019.1.0f1, 2018.3.12f

Note:
- reproducible with IL2CPP and .NET backends
- not reproducible when building Standalone (mono/IL2CPP)

UnityException: Failed to run reference rewriter with command "--target=Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" "--target=Temp\StagingArea\Data\Managed\UnityEngine.Timeline.dll"
<...>
Catastrophic failure while running rrw: System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
at Mono.Cecil.PE.ImageReader.ReadOptionalHeaders(UInt16& subsystem, UInt16& dll_characteristics) in C:\buildslave\cecil\build\Mono.Cecil.PE\ImageReader.cs:line 186
at Mono.Cecil.PE.ImageReader.ReadImage() in C:\buildslave\cecil\build\Mono.Cecil.PE\ImageReader.cs:line 86
at Mono.Cecil.PE.ImageReader.ReadImage(Disposable`1 stream, String file_name) in C:\buildslave\cecil\build\Mono.Cecil.PE\ImageReader.cs:line 754
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) in C:\buildslave\cecil\build\Mono.Cecil\ModuleDefinition.cs:line 1097
at Unity.SearchPathAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters) in C:\buildslave\unity\build\Tools\Unity.NuGetPackageResolver\SearchPathAssemblyResolver.cs:line 52
at Unity.ReferenceRewriter.RewriteAssemblyManifest.RewriteAssemblyReference(AssemblyNameReference reference) in C:\buildslave\unity\build\Tools\rrw\RewriteAssemblyManifest.cs:line 55
at Unity.ReferenceRewriter.RewriteAssemblyManifest.Run() in C:\buildslave\unity\build\Tools\rrw\RewriteAssemblyManifest.cs:line 34
at Unity.ReferenceRewriter.RewriteOperation.Execute(RewriteContext context) in C:\buildslave\unity\build\Tools\rrw\RewriteOperation.cs:line 24
at Unity.ReferenceRewriter.Program.Main(String[] args) in C:\buildslave\unity\build\Tools\rrw\Program.cs:line 106
<...>

  1. Response avatar

    Resolution Note (fix version 2019.3):

    This is a bug in the package, not Unity. The package has an .asmdef file that makes C# code to be compiled into "HFAsyncTexture.dll", and it also has a native DLL with the exact same name. This causes a conflict.

Comments (4)

  1. 7fd630127a2ccfc75f8abca4e43d6e3b?d=mm

    Tautvydas-Zilys

    May 11, 2019 01:47

    Adam, that was indeed the issue on this project as well. On Android and iOS, native plugins don't have .dll file extension, so this conflict never comes up.

  2. E2034f7753b52d221306edf828d6353e?d=mm

    Adam-VisualVocal

    Apr 26, 2019 02:53

    I figured out the cause of this, at least in my project. My native DLL has a thin managed C# wrapper around it that is built into an assembly via an assembly definition (.asmdef) file. Without thinking about it, I had used the same name for both the assembly and the native DLL. On Android and iOS that seems to work but in a UWP build it causes the BadImageFormatException. That's probably because that part of the build process is looking for the assembly DLL but unfortunately finds the like-named native DLL instead. The solution for me was to just rename the assembly and now all is well. I hope that works for the OP too.

  3. E2034f7753b52d221306edf828d6353e?d=mm

    Adam-VisualVocal

    Apr 24, 2019 19:06

    I see this in Unity 2018.3.13f1.

  4. E2034f7753b52d221306edf828d6353e?d=mm

    Adam-VisualVocal

    Apr 24, 2019 19:05

    Me too. I have several native DLLs in my project and I hit the same System.BadImageFormatException from the reference rewriter. Why would RRW even be trying to process native DLLs? I suspect that's the issue. Probably the Unity build process shouldn't run RRW on native DLLs at all.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.