I have a project and I use GitHub in order to save each new steps. However, since few days, I just got a Mac and I worked on this project from a Windows OS before.
So, I installed Xamarin for Mac and cloned my git repo. But.. Mac doesn't want to compile the Android project part, I don't understand why but it throws Error MSB4018: The "CheckDuplicateJavaLibraries" task failed unexpectedly.. I created a new Forms Project from my Mac machine and, it does compile. So, I was like "Ok, let's create a new solution from windows (maybe the previous one is obsolete)", but the error come back...
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(3,3): Error MSB4018: The "CheckDuplicateJavaLibraries" task failed unexpectedly.
System.IO.FileNotFoundException: Could not find file 'obj/Debug/__library_projects__/Xamarin.Android.Support.Animated.Vector.Drawable/library_project_imports/classes.jar'.
File name: 'obj/Debug/__library_projects__/Xamarin.Android.Support.Animated.Vector.Drawable/library_project_imports/classes.jar'
at System.IO.__Error.WinIOError (System.Int32 errorCode, System.String maybeFullPath) [0x00207] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/io/__error.cs:188
at System.IO.FileInfo.get_Length () [0x00038] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/io/fileinfo.cs:171
at (wrapper remoting-invoke-with-check) System.IO.FileInfo:get_Length ()
at Xamarin.Android.Tasks.MonoAndroidHelper+SizeAndContentFileComparer.GetHashCode (System.IO.FileInfo obj) [0x00001] in /Users/builder/data/lanes/4695/9dbc4c53/source/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs:101
at System.Linq.Set`1[TElement].InternalGetHashCode (TElement value) [0x00000] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq/src/System/Linq/Set.cs:206
at System.Linq.Set`1[TElement].Add (TElement value) [0x00000] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq/src/System/Linq/Set.cs:74
at System.Linq.Enumerable+DistinctIterator`1[TSource].MoveNext () [0x00083] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq/src/System/Linq/Distinct.cs:72
at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].ToArray () [0x00030] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq/src/System/Linq/Select.cs:155
at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00015] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:19
at Xamarin.Android.Tasks.MonoAndroidHelper.DistinctFilesByContent (System.Collections.Generic.IEnumerable`1[T] filePaths) [0x00001] in /Users/builder/data/lanes/4695/9dbc4c53/source/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs:164
at Xamarin.Android.Tasks.CheckDuplicateJavaLibraries.Execute () [0x000fb] in /Users/builder/data/lanes/4695/9dbc4c53/source/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs:29
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/msbuild-15.0/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:632
at Microsoft.Build.BackEnd.TaskBuilder+<ExecuteInstantiatedTask>d__26.MoveNext () [0x00249] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/msbuild-15.0/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:787 (MSB4018) (AppTESTwindows.Android)
It seems like a Xamarin Forms android project from windows cannot be compiled on Mac. But the thing is, from Mac, you cannot manage the NuGet packages and it doesn't create the UWP side...
I then tried to two following solutions:
Windows to iOS - Xamarin Forms PCL project created from Windows and compiled on Mac
Cannot be compiled (Error MSB4018)
NuGet packages cannot be managed
iOS to Windows - Xamarin Forms PCL project created from Mac and compiled on Windows
Can be compiled
NuGet packages cannot be managed on the PCL part (only Android/iOS)
The UWP side of the project doesn't exist
I don't understand because I almost spent a day on it and I can't find anything on the internet... They just say that NuGet isn't available on Mac, so alright, why not, but it means that I need to create the solution from windows then? However, I can't manage the NuGet packages of the shared part (PCL).
It's also weird because I can't believe that we can't work from Mac and Windows on the same solution, how does work teammates that share a project over git then?
If you can explain to me what I didn't understand, then please reply.. I need to work often outside of my house and, I need to manage my nuget packages...
Thank in advance !
Related
From what I googled, I could not find solution.
UrhoSharp GIT, is solution built with VS2015.
I created new Xamarin mobile platform solution.
Copied the relevant files over from sample UrhoSharp project.
Then ran the Windows(UWP) propject. it crashes.
(I did it this way as there were too many issues with building the sample project that was created in VS2015)
protected Sample(ApplicationOptions options) : base(options) { }
Throws an exception.
System.Exception
HResult=0x80131500
Message=Implementation assembly (iOS, Android or Desktop) is not referenced
Source=UrhoSharp
at Urho.UrhoPlatformInitializer.DefaultInit()
Try to update to latest UrhoSharp package (1.9.67 at this moment), clean and rebuild the whole solution. It helped in my case.
I'm able to build the app in Windows on the latest version of VS2017 (15.9.2) for both Android and iOS, and I'm able to use the Remote iOS Simulator to run my iOS app as built on my Mac. However, when I use the same solution on my 2009 iMac on High Sierra in Visual Studio for Mac, I get an exception on one of my .NET Standard libraries from sgen.exe when msbuild attempts to generate the serialization assemblies:
Unhandled Exception:
System.TypeLoadException: Could not load type of field '<TYPENAME>+<>c__DisplayClass3_0:obj' (0) due to: Could not load file or assembly 'Newtonsoft.Json,
Version=12.0.0.0,
Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.
To try to get past this, I commented out the class that is failing (within cs in the exception above) along with the using statements in that file related to Newtonsoft.Json. After doing this, I get the following exception:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
at System.Xml.Serialization.XmlSerializationWriterCodeGen.FindXmlnsIndex (System.Xml.Serialization.MemberMapping[] members) [0x00014] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializationWriterCodeGen.WriteStructMethod (System.Xml.Serialization.StructMapping mapping) [0x00359] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateMethod (System.Xml.Serialization.TypeMapping mapping) [0x00024] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializationCodeGen.GenerateReferencedMethods () [0x0001b] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateEnd () [0x00000] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.TempAssembly.GenerateAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence, System.Xml.Serialization.XmlSerializerCompilerParameters parameters, System.Reflection.Assembly assembly, System.Collections.Hashtable assemblies) [0x003a7] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializer.GenerateSerializer (System.Type[] types, System.Xml.Serialization.XmlMapping[] mappings, System.CodeDom.Compiler.CompilerParameters parameters) [0x000cb] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at Driver.Run (System.String[] args) [0x0042c] in <4ef54e9b09fa46d8995a283d81fa42c0>:0
at Driver.Main (System.String[] args) [0x00005] in <4ef54e9b09fa46d8995a283d81fa42c0>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at System.Xml.Serialization.XmlSerializationWriterCodeGen.FindXmlnsIndex (System.Xml.Serialization.MemberMapping[] members) [0x00014] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializationWriterCodeGen.WriteStructMethod (System.Xml.Serialization.StructMapping mapping) [0x00359] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateMethod (System.Xml.Serialization.TypeMapping mapping) [0x00024] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializationCodeGen.GenerateReferencedMethods () [0x0001b] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializationWriterCodeGen.GenerateEnd () [0x00000] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.TempAssembly.GenerateAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence, System.Xml.Serialization.XmlSerializerCompilerParameters parameters, System.Reflection.Assembly assembly, System.Collections.Hashtable assemblies) [0x003a7] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at System.Xml.Serialization.XmlSerializer.GenerateSerializer (System.Type[] types, System.Xml.Serialization.XmlMapping[] mappings, System.CodeDom.Compiler.CompilerParameters parameters) [0x000cb] in <9e212f4dac634c83bb98a320d2c5ec4d>:0
at Driver.Run (System.String[] args) [0x0042c] in <4ef54e9b09fa46d8995a283d81fa42c0>:0
at Driver.Main (System.String[] args) [0x00005] in <4ef54e9b09fa46d8995a283d81fa42c0>:0 /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(3553, 5): error MSB6006: "sgen.exe" exited with code 1. Done building target "GenerateSerializationAssemblies" in project "<PROJECTNAME>.csproj" -- FAILED.
I've also tried the following:
Changing the linker behavior from anything to not linking at all to linking everything. There was no difference.
Setting "Generate Serialization Assembly" to "Off" in the project settings. The app built in Windows, but while loading it crashes. There does not appear to be an option to control this in Visual Studio for Mac.
Changing all PCL projects to .NET Standard 2.0 projects and changing all Xamarin Droid or iOS projects to use PackageReferences instead of the package.config
Adding the latest version of Newtonsoft.Json to all projects in the solution
Updated Mono, Xamarin and VS for Mac to the latest versions
Does anybody have any ideas? Again, both iOS and Android builds seem to work in Visual Studio 2017 on Windows, but they do not on my Mac. Thanks in advance for your help!
Sorry for all the long error messages! I wonder if there is something wrong with my Xamarin, or Mono install which is breaking FSI on Xamarin? Default .Net runtime is Mono 4.6.2 Although I have installed Mono 4.8.0, Xamarin is running on 4.6.2
I wonder if these error messages mean that FSI isn't loading the System.Drawing module? And why is SOURCE_DIRECTORY seemingly not working? There are no errors displayed in the .fsx file but when loaded into FSI it doesn't work.
I've also got Visual Studio for Mac installed. I'm just starting with F# (day 3) and this is the first time I've tried to open a System module so I've not idea if it ever worked. Basic functions I write myself will evaluate in FSI. I'm considering the possibility that the install has been screwed up somewhere and am wondering if I should just remove .Net, Xamarin and Mono and reinstall from scratch? Is it possible for Visual Studio to interfere with Xamarin?
Going through the FSharp TV intro course I'm running the following errors
F# in a .fsx file:
open System.Drawing
let bitmap = new Bitmap(32,32)
let path = __SOURCE_DIRECTORY__ + "/"
bitmap.Save (path + "large.png")
Loading the entire code block in FSI throws:
System.Exception: Generic Error [GDI+ status: GenericError]
at System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status status) [0x0007a] in <1917aa1c39d94b1a91807b8cd9f03350>:0
at System.Drawing.Image.Save (System.String filename, System.Drawing.Imaging.ImageCodecInfo encoder, System.Drawing.Imaging.EncoderParameters encoderParams) [0x00043] in <1917aa1c39d94b1a91807b8cd9f03350>:0
at System.Drawing.Image.Save (System.String filename, System.Drawing.Imaging.ImageFormat format) [0x0004c] in <1917aa1c39d94b1a91807b8cd9f03350>:0
at System.Drawing.Image.Save (System.String filename) [0x00008] in <1917aa1c39d94b1a91807b8cd9f03350>:0
at (wrapper remoting-invoke-with-check) System.Drawing.Image:Save (string)
at <StartupCode$FSI_0004>.$FSI_0004.main# () [0x0003d] in <2545683d6122431b9ff3a69ce9ec460c>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <8f2c484307284b51944a1a13a14c0266>:0
Loading only SOURCE_DIRECTORY in FSI returns:
val it : string = "/"
which is weird because that's not the correct path
Loading the line: let bitmap = new Bitmap(32,32)
throws:
Stopped due to error
System.Exception: Operation could not be completed due to earlier error
The type 'Bitmap' is not defined at 2,4
Sending System.Drawing to FSI
throws:
Stopped due to error
System.Exception: Operation could not be completed due to earlier error
The value, constructor, namespace or type 'Drawing' is not defined at 2,7
It looks like you might be hitting a Mono bug. I've found several reports of what looks like the same bug (though it's possible that it's several different bugs). The most useful one appears to be this Github issue: https://github.com/gitextensions/gitextensions/issues/2226
I don't know if that will help you; that issue appears to have been resolved by upgrading from Mono 3.2.8 to the latest version of Mono available at the time. But you're already running what appears to be the latest version of Mono available to you, so "upgrade to the latest Mono" may not be the advice for your problem. But it's the best advice I'm able to give.
Also, in doing that search, I found several people complaining that libgdiplus (Mono's implementation of the GDIPlus API) was buggy in various ways. So in your shoes, I might skip the System.Drawing examples and move on to a different part of the tutorial if you can't get libgdiplus to work.
P.S. The below is what I first wrote in answer to your question, but then I experimented and discovered that the System.Drawing namespace is automatically loaded in F# scripts without you needing to explicitly open it. Still, as an F# beginner, you may find the information below to be useful in other contexts, so I've left it in. Just be aware that what I said below about System.Drawing not being automatically opened was wrong.
----- Not-quite-correct answer follows -----
When writing an F# script in a .fsx file, you can't just do open (namespace). You also have to tell F# where to find the .DLL with that namespace. In a compiled project (which uses .fs files), that information would be found in the .fsproj file. But for F# scripts (the .fsx format), there's no project file, so the script itself needs to specify which DLLs to load. You do this by the #r directive:
#r "/path/to/library.dll"
Or, if the DLL you're loading is installed in a standard system location such as the GAC (Global Assembly Cache), you can leave off the path and just do:
#r "library.dll"
There are a few DLLs that are automatically loaded whenever you run an F# script, such as mscorlib.dll that contains things like the System namespace. But the System.Drawing namespace is not one of those automatically-loaded DLLs. So before you can open the System.Drawing namespace, you have to put in the appropriate #r reference, like so:
#r "System.Drawing.dll"
open System.Drawing
I just upgraded to Xamarin studio 5.9 (build 431), and cannot run my project anymore. It works with a clean project though.
When I run my app, I don't even land in Main.
The Application Output in Xamarin studio prints a bunch of assembly loadings. It gets to MobileClientiOS.app/Newtonsoft.Json.dll [External], then it crashes with the following output:
Could not load file or assembly 'System.Threading.Tasks' or one of its
dependencies. The system cannot find the file specified.
(System.IO.FileNotFoundException) at System.AppDomain.Load
(System.Reflection.AssemblyName assemblyRef,
System.Security.Policy.Evidence assemblySecurity) [0x00081] in
.../mono/mcs/class/corlib/System/AppDomain.cs:706 at
System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef)
[0x00000] in .../mono/mcs/class/corlib/System/AppDomain.cs:674 at
System.Reflection.Assembly.Load (System.Reflection.AssemblyName
assemblyRef) [0x00000] in
.../mono/mcs/class/corlib/System.Reflection/Assembly.cs:551 at
ObjCRuntime.Runtime.CollectReferencedAssemblies
(System.Collections.Generic.List 1 assemblies,
System.Reflection.Assembly assembly) [0x00019] in
.../maccore/src/ObjCRuntime/Runtime.cs:218 at
ObjCRuntime.Runtime.CollectReferencedAssemblies
(System.Collections.Generic.List 1 assemblies,
System.Reflection.Assembly assembly) [0x0002c] in
.../maccore/src/ObjCRuntime/Runtime.cs:220 at
ObjCRuntime.Runtime.CollectReferencedAssemblies
(System.Collections.Generic.List 1 assemblies,
System.Reflection.Assembly assembly) [0x0002c] in
.../maccore/src/ObjCRuntime/Runtime.cs:220 at
ObjCRuntime.Runtime.RegisterEntryAssembly (System.Reflection.Assembly
entry_assembly) [0x0001b] in
.../maccore/src/ObjCRuntime/Runtime.cs:200 at
ObjCRuntime.Runtime.RegisterEntryAssembly (IntPtr a) [0x00000] in
.../maccore/src/ObjCRuntime/Runtime.cs:158 at
ObjCRuntime.Runtime.register_entry_assembly (IntPtr assembly)
[0x00000] in .../maccore/runtime/Delegates.generated.cs:118 at
(wrapper native-to-managed)
ObjCRuntime.Runtime:register_entry_assembly (intptr) 2015-05-04
MobileClientiOS[77830:1943120] critical: Got a SIGABRT while
executing native code. This usually indicates a fatal error in the
mono runtime or one of the native libraries used by your application.
Sorry for the long stacktrace, but I'm out of ideas. We are using PCL's, but there haven't been a problem before this Xamarin Studio-upgrade.
Thank you!
Edit:
I downgraded Xamarin.iOS and it's working again. The assembly it seems to fail on is (which now works with the old version):
/MobileClientiOS.app/System.Xml.Linq.dll [External]
How to be able to run with the latest version? I do not know.
To make a guess, I think this might have the same underlying cause as Xamarin Bug 29211.
If that's true, then there's a good chance the same workaround will work:
Under "project options -> iOS Build -> Additional mtouch arguments" add:
-linkskip=System.Threading.Tasks
If that workaround does indeed work, then it's very likely the issue will be fixed in the upcoming service release (due to be released later this week).
Update July 2, 2015
It turns out there is another subtly different common cause of the problem for System.Threading.Tasks. That second bug was originally hidden by Bug 29211 because the two bugs are very similar. The second problem is now being tracked in Xamarin Bug 31560. Note that this bug only affects simulator builds and has fairly simple workarounds, so it is minor in severity.
I am making an android app in xamarin studio and it needs to have google play services because of google maps api v2 and a QR code scanner for mobile. But when I added zxing.net.mobile to my packages after I had set up google maps and gotten the google play services package, they both fail as they are both dependent on the 'Xamarin.Android.Support.v4' package.
I have tried this on two different solutions and the same thing happens.
I have looked into this on google and stack overflow and found dependency hell on wikipedia, but I can not seem to apply that to NuGet packages when using Xamarin Studio. Dependency hell on wikipedia
And i found this reason for it: Question answer without full explanation on how to do this.
So how does this work, where do I look to change to only using Xamarin.Android.Support.V4 for both ZXing.net and google play services?
Error:
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2): Error: Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Xamarin.Android.Support.v4.dll'
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute() (TrailMapplication)
Figured out what I had to do, and it solved that problem: I went to my project on my computer and looked into
C:\Users\Name\Documents\Projects\Solution\Project\bin\Debug
and deleted a Mono.Android.Services.v4.dll and added the Xamarin.Android.Services.v4.dll instead.
Had to Re-build the project though but then it worked.