mono touch Can not resolve reference: System.Reflection.Emit.AssemblyBuilder - deployment

Monotouch deploy error:
if I use System.Reflection ( I think that is the reason)
I get the following error when I try to deploy
Could not link assemblies: Mono.Linker.ResolutionException: Can not resolve reference: System.Reflection.Emit.AssemblyBuilder
at Mono.Linker.Steps.MarkStep.ResolveTypeDefinition (Mono.Cecil.TypeReference type) [0x00000] in :0
at Mono.Linker.Steps.MarkStep.MarkType (Mono.Cecil.TypeReference reference) [0x00000] in :0
at Mono.Linker.Steps.MarkStep.MarkMethodBody (Mono.Cecil.Cil.MethodBody body) [0x00000] in :0
at Mono.Linker.Steps.MarkStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00000] in :0
at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00000] in :0
at Mono.Linker.Steps.MarkStep.Process () [0x00000] in :0
at Mono.Linker.Steps.MarkStep.Process (Mono.Linker.LinkContext context) [0x00000] in :0
at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00000] in :0
at MonoTouch.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in :0
Everything works fine in Simulator. If I don't use the library, I can deploy the app with no issues.

System.Reflection.Emit is not supported by Monotouch. It is because all the code must be existing in the binary and is actually linked by the linker after being created by ahead of time compiler. If you will be emitting the code from C# there is no way how it gets compiled on runtime to binary code as there is no full .NET runtime on iPhone.
Anyway, even if there would be a way how to compile on runtime to binary and link it (very complex issue BTW) this would violate Apple's approval guidelines, where it says that Apps cannot download code of any sort and change its behaviour on the fly.
So all in all, avoid reflection as such.

Related

System.IO.ports works in Unity but not in build

I threw together a little application in Unity which needs to access a serial port. Since Unity does not include System.IO.Ports I installed the NugetPackage with NugetForUnity. Everything works fine in the engine but if I build the project it somehow can't use System.IO.Ports anymore.
NotSupportedException: System.IO.Ports.SerialPort::.ctor
at System.IO.Ports.SerialPort..ctor (System.String portName, System.Int32 baudRate, System.IO.Ports.Parity parity, System.Int32 dataBits, System.IO.Ports.StopBits stopBits) [0x00000] in <00000000000000000000000000000000>:0
at GetInput.Start () [0x00000] in <00000000000000000000000000000000>:0
I got it to work by changing the "Scripting Backend" to "Mono" and building the solution in Visual Studio.

Unity ECS/Burst on IOS

I have created a new project using Unity 2019.3.0f6 under macOS Mojave.10.14.6
Added a simple cube to the scene and included the following packages from the Package Manager:
Entities preview.11 - 0.5.1
Burst 1.2.2
I can build the project fine on Unity as Release and it builds successfully on xCode(v11.3.1).
But when I try to run it on iPhone X device with IOS 13.3.1 I am getting the following exception:
NotSupportedException: To marshal a managed method, please add an
attribute named 'MonoPInvokeCallback' to the method definition. The
method we're attempting to marshal is:
Unity.Entities.StructuralChange::AddComponentEntitiesBatchExecute at
Unity.Burst.BurstCompiler.Compile[T] (T delegateObj, System.Boolean
isFunctionPointer) [0x00000] in <00000000000000000000000000000000>:0
at Unity.Entities.StructuralChange.Initialize () [0x00000] in
<00000000000000000000000000000000>:0 at
Unity.Entities.EntityManager..ctor (Unity.Entities.World world)
[0x00000] in <00000000000000000000000000000000>:0 at
Unity.Entities.World..ctor (System.String name) [0x00000] in
<00000000000000000000000000000000>:0 at
Unity.Entities.DefaultWorldInitialization.Initialize (System.String
defaultWorldName, System.Boolean editorWorld) [0x00000] in
<00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)
Any idea why this is happening with a simple project?

Cannot build Unity project from command line on fresh git cloned repository

I am looking to build Unity project just after git cloning them. However when they are "fresh" (only not giignored files) the build is very short and has no output. I have to open once the project with Unity Editor to make the build command line working.
Build command line:
D:/------/Unity.exe -quit -batchmode -logFile uniytBuildLog.txt -buildTarget Win64 -executeMethod AutoBuilder.PerformBuild -appName test.exe -buildFolder "./Build/"
End of build log that seems to be a succes despite a strange error
Reloading assemblies after script compilation.
Begin MonoManager ReloadAssembly
Refreshing native plugins compatible for Editor in 3.09 ms, found 7 plugins.
Preloading 2 native plugins for Editor in 0.15 ms.
Mono: successfully reloaded assembly
Refreshing native plugins compatible for Editor in 0.79 ms, found 7 plugins.
Preloading 2 native plugins for Editor in 0.11 ms.
----- Total AssetImport time: 0.130863s, AssetImport time: 0.000000s, Asset hashing: 0.000000s [0 B, 0.000000 mb/s]
- Completed reload, in 1.564 seconds
Initializing Unity.PackageManager (PackageManager) v2017.2.1 for Unity v2017.2.1f1
Registering platform support modules:
Registered platform support modules in: 0.0496396s.
Native extension for OSXStandalone target not found
Native extension for WindowsStandalone target not found
Native extension for LinuxStandalone target not found
Native extension for WebGL target not found
Native extension for Metro target not found
Native extension for iOS target not found
Native extension for Android target not found
Batchmode quit successfully invoked - shutting down!
Refresh: detecting if any assets need to be imported or removed ... Refresh: elapses 0.046037 seconds (Nothing changed)
Updating ProjectSettings/ProjectSettings.asset - GUID: 00000000000000004000000000000000...
done. [Time: 61.503121 ms]
Refreshing native plugins compatible for Editor in 1.32 ms, found 7 plugins.
Preloading 2 native plugins for Editor in 0.12 ms.
----- Total AssetImport time: 0.196505s, AssetImport time: 0.107053s, Asset hashing: 0.000000s [0 B, 0.000000 mb/s]
Refresh: detecting if any assets need to be imported or removed ... Refresh: elapses 0.032108 seconds (Nothing changed)
[Package Manager] Server::Kill -- Server was shutdown
Cleanup mono
[usbmuxd] Stop listen thread
[usbmuxd] Listen thread exiting
Exiting batchmode successfully now!
Unhandled Exception: System.IO.DirectoryNotFoundException: Directory 'C:\Users\Ben\AppData\Local\Temp\160279e2' not found.
at System.IO.Directory.GetFileSystemEntries (System.String path, System.String searchPattern, FileAttributes mask, FileAttributes attrs) [0x000f7] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:514
at System.IO.Directory.GetDirectories (System.String path, System.String searchPattern) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:275
at System.IO.Directory.GetDirectories (System.String path) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:270
at System.IO.Directory.RecursiveDelete (System.String path) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:186
at System.IO.Directory.Delete (System.String path, Boolean recursive) [0x0000c] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:205
at System.CodeDom.Compiler.TempFileCollection.Delete () [0x00000] in <filename unknown>:0
at System.CodeDom.Compiler.TempFileCollection.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0
at System.CodeDom.Compiler.TempFileCollection.Finalize () [0x00000] in <filename unknown>:0
debugger-agent: Unable to listen on 3896
One of the problem was due to the lack of the argument with the project path.
I was thinking that skipping this argument would use the project in the current directory but it uses instead the last opened project so it was not building the right one until I open it with the Editor.

Facebook.Unity.Gameroom.dll was not registered

Unity3D version 2017.1.1f1
Whenever I launch Unity, I get the following error:
Assertion failed: Extension
Library/FacebookSDK/Facebook.Unity.Gameroom.dll was not registered,
that means it relies on default UnityExtensions settings, please
register extension and apply necessary settings for it in the
callback. I tried deleting the Library folder but the problem is still
there and the file Facebook.Unity.Gameroom.dll also exists.
Also when I try to build for WebGL, 3 more errors are shown and build fails. The first one is as follows:
ArgumentException: The Assembly Facebook.Unity is referenced by
Facebook.Unity.Gameroom
('Library/FacebookSDK/Facebook.Unity.Gameroom.dll'). But the dll is
not allowed to be included or could not be found.
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse
(System.String assemblyPath, System.Collections.Generic.List1
alreadyFoundAssemblies, System.String[] allAssemblyPaths,
System.String[] foldersToSearch,
System.Collections.Generic.Dictionary2 cache, BuildTarget target) (at
C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:142)
UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[]
paths, System.String[] foldersToSearch, BuildTarget target) (at
C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:179)
UnityEditor.HostView:OnGUI()
How can I solve this?

Is it possible to build iPhone app with MonoTouch using Microsoft managed EWS?

I'm trying to build iOS app using Microsoft EWS managed API. I've downloaded the msi from http://www.microsoft.com/download/en/details.aspx?id=13480 and copied the DLL under the solution folder.
When building for the simulator, it builds and runs fine, but when trying to target the physical device, mtouch fails with:
Compiling to native code
/Developer/MonoTouch/usr/bin/mtouch -v --nomanifest --nosign -dev "/Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -r "/Users/Projects/HelloMonoTouch/MyEWSApp/ThirdParty/Microsoft.Exchange.WebServices.dll" -linksdkonly -sdk "5.0" "/Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.exe"
Framework is: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
Copied /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.exe to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/MyEWSApp.exe
Copied /Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/mscorlib.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/monotouch.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/System.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/Mono.Security.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/Mono.Security.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/System.Core.dll
Copied /Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/System.Xml.dll
Copied /Users/Projects/HelloMonoTouch/MyEWSApp/ThirdParty/Microsoft.Exchange.WebServices.dll to /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app/Microsoft.Exchange.WebServices.dll
Linking SDK only for assembly /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.exe into /Users/Projects/HelloMonoTouch/MyEWSApp/bin/iPhone/Release/MyEWSApp.app
Could not link assemblies: System.IO.FileNotFoundException: Could not resolve: System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0
at Mono.Linker.AssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0
at Mono.Linker.LinkContext.Resolve (IMetadataScope scope) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.LoadReferencesStep.ProcessAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
at MonoTouch.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
mtouch exited with code 1
I diligently added:
System.DirectoryServices.dll
System.Configuration.dll
System.Security.dll
System.DirectoryServices.Protocols.dll
System.EnterpriseServices.dll
with a growing feeling of not being on the right track, but when mtouch complained about native System.EnterpriseServices.Wrapper.dll, I gave up.
I've tried to play with Project Options/iPhone build SDK and Linker options.
I've also tried both 32-bit and 64-bit versions of Microsoft.Exchange.WebServices.dll
P.S. I know that I could consume EWS without Managed EWS API, but writing and parsing all these XML requests and responses is such a pain.
Both the MonoTouch's linker and the AOT compiler needs all dependencies to be present when doing their work. That, and missing symbols (types, methods...), makes it hard (but not totally impossible) to re-use pre-built binaries from another version of the framework.
It also explains why this can sometime (no missing symbols) work on the simulator. By default the simulator builds are set to "Don't link" (no linker) and the JIT (no AOT) is used. This allows missing references/symbols to go unnoticed... until they are (potentially never) needed.
You can turn off the linker for device builds - but that won't help the AOT compiler. OTOH you can try to satisfy the linker and it could be able to remove enough of the code to let the AOT compiler do its work properly. Sadly when things go down to native code, like System.EnterpriseServices.Wrapper.dll, your options becomes much more limited.
You cannot use a Windows DLL with MonoTouch - it is not compiled for the iOS architecture. You have to either have a DLL that was compiled specifically for MonoTouch, or if you have the source you can build it yourself.