Embeddinator-4000 icon indicating copy to clipboard operation
Embeddinator-4000 copied to clipboard

[ObjC] The assembly mscorlib.dll was not found in Embedinated Umbrella Framework iOS used by Swift

Open emysa341 opened this issue 6 years ago • 1 comments

I have a C# project, after embedination I get a nicely wrapped Objective-C framework. If I consume this project in any iOS application (Objective-C/Swift) works fine. If I try to consume this objective-c based framework nested inside a swift based framework -> Then in client application it results into dll not found errors:

Error-Highlights-> The assembly mscorlib.dll was not found or could not be loaded.

Test Suite 'Selected tests' started at 2017-12-15 14:25:22.837 Test Suite 'ConsumerTests.xctest' started at 2017-12-15 14:25:22.838 Test Suite 'ConsumerTests' started at 2017-12-15 14:25:22.838 Test Case '-[ConsumerTests.ConsumerTests testForTestingUmrellaFramework]' started. 2017-12-15 14:25:22.846091+0100 xctest[13921:651806] The assembly mscorlib.dll was not found or could not be loaded. 2017-12-15 14:25:22.846237+0100 xctest[13921:651806] **It should have been installed in the /Users/builder/data/lanes/5665/6857dfcc/source/xamarin-macios/builds/install/simulator64/lib/mono/2.1/mscorlib.dll directory.** Program ended with exit code: 1

  • I am using module mapping approach to use objective-c within swift framework, since bridging header only works for app targets.
  • I am posting a sample project to reproduce this issue. My enclosures contains following files: -- C# Project (CSharp) CSharp.zip -- Framework generated by Embedinator (CSharp.framework) CSharp.framework.zip -- A swift based consumer project. (Consumer) Consumer.zip

So I embedinated a csharp project to objective-C framework "CSharp.framework" and then I use "CSharp.framework" in swift based framework named "Consumer.framework" then I use "Consumer.framework" in Consumer.Tests then it fails with above errors and Its not a project configuration problem its embedination problem. Because I also created same project structure without embedination everything works fine but after embedination these dll problems arise. To Reproduce the issue, open consumer project and run the test with name "testForTestingUmrellaFramework".

  • In order to find a workaround, instead of generating framework I generated dynamic library. Now, result of embedination contains following files: files

  • I was not sure which dylib file I have to use then I ran lipo -info libCSharp.dylib (file next to glib.h) command in terminal then I get following output: Architectures in the fat file: /Users/xamarindev/Projects/CSharp/CSharp/bin/Debug/lib/libCSharp.dylib are: i386 x86_64 armv7 armv7s arm64

  • This files contain all standard architecture so instead of using framework I used this file.

  • In my swift framework project I imported this and set the library path and header search path to the folder above.

  • Also to reference the c# classes there was no separate class so I referenced bindings.h file. (In CSharp.framework scenario there was a header file with the name CSharp.h which included all other header file. -> This can be seen if you open the CSharp.framework/Headers/CSharp.h)

After running the test now I get different dll errors:

Error-Highlight-> Library not loaded: rpath/libxamarin.dylib, Referenced from libCSharp.dylib

2017-12-15 15:25:00.374771+0100 xctest[15351:798149] The bundle “ConsumerTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. 2017-12-15 15:25:00.375526+0100 xctest[15351:798149] (dlopen_preflight(/Users/xamarindev/Library/Developer/Xcode/DerivedData/Consumer-higzelgkqqwzakbnjwdlroihgdil/Build/Products/Debug-iphonesimulator/ConsumerTests.xctest/ConsumerTests): Library not loaded: @rpath/libxamarin.dylib **Referenced from: /Users/xamarindev/Library/Developer/Xcode/DerivedData/Consumer-higzelgkqqwzakbnjwdlroihgdil/Build/Products/Debug-iphonesimulator/Consumer.framework/Frameworks/libCSharp.dylib** Reason: image not found) Program ended with exit code: 82

Conclusion : If embedinated framework or libary is used in Umbrella frameworks (Nested frameworks) then it results into dll not found errors. Following are enclosures:

emysa341 avatar Dec 15 '17 13:12 emysa341

This gets into more swift / iOS than I know, but at first look appears to be some sort of packaging issue (?)

chamons avatar Mar 20 '18 16:03 chamons