il-repack
il-repack copied to clipboard
The type 'XXXXX' is defined in an assembly that is not referenced.
After using ILRepack within the cake script. Repacking works like charm, successfully producing a merged DLL. I am repacking around 15 dll files. The end result is single dll file. All the dll files I am repacking has a different assembly name. At the end when I try to use the repacked dll file in a project then I get errors in type resolution with error:
The type 'XXXXX' is defined in an assembly that is not referenced. You must add a reference to assembly 'MyAssembly-1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Although the Assembly-1 exists within the primary assembly, which I actually merged. If I add it again seperately then the purpose of using ILRepack is compromised. Also when I try to consume any namespace from MyAssembly-1, it works fine I am able to include the namespaces. Following is the structure of my resultant dll file:
- Primary-Assembly (netstandard 2.0) ---MyAssembly-1 (netstandard 2.0) ---MyAssembly-2 (netstandard 2.0) ---MyAssembly-3 (netstandard 2.0) ---MyAssembly-N.(netstandard 2.0)
- MyiOS-Assembly (Xamarin.iOS10) (Class Library)
Consumer-iOS-Project = Using Primary-Assembly + MyiOS-Assembly results into above error. This setup can't find the dll which are packed. This only happens when I use ILRepack. Same problem while using
Consumer-Android-Project = Using Primary-Assembly + MyAndroid-Assembly
Also I have been navigating around in the issues section but countn't find out the workaround for this issue. Can someone point out me in the right direction.
ILRepack version: 2.014/2.015 using Cake build.
Update: After analysing the following error: Argument type "YYYYY" [Primary-Assembly, version 1.0.0.0] is not assignle to type "YYYYY"[MyAssembly-1,version 1.0.0.0].
The type in actual exists in the MyAssembly-1. While the error message shows that the type "YYYYY" I am accessing from dll (Produced by ILRepack.) exists in Primary-Assembly (as per above error), while in actual type "YYYYY" exists in MyAssembly-1. This shows that the ILRepack is assigning assembly name of primary assembly (Primary-Assembly-1) to all other assemblies. This is why there are referencing errors.
@emysa341 this error is most likely not a bug in ILRepack, you're correct in saying that ILRepack (exactly like ILMerge) will rename / move all classes under the scope / assembly of the merged one. It makes sense if you want to hide your dependencies from client code, but only works if the client code doesn't access/uses these (merged) assemblies (in your case it could be that iOS/Android projects are compiled targeting MyAssembly-1, they will only run if MyAssembly-1 is provided, which hence can't be merged).
If you find out which code is throwing the original "defined in an assembly that is not referenced" exception, you may find which component is using MyAssembly-1, typically 2 cases:
- an unmerged one
- hard-coded reflection referencing MyAssembly-1
- generated code referencing MyAssembly-1
Good luck.