Reputation: 720
First let make clear that this is my first Android project ever that I'm trying to complete, so I'm still very new to all this. I've been stuck with this extremely annoying problem where I can't compile my project anymore even after removing a lot things. At one point in my project I added the 'System' namespace to use the 'Exception' keyword(to test a DB connection). All was working fine and well right before this point. But after trying to compile I got the error:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile? File name: 'System.Drawing.dll'
So I just added 'using System.Drawing' on top but later I read that Xamarin Android doesn't support that. So I removed it again and tried to remove whatever I did to try stop getting this Exception. Then this error got stuck forever even if I comment all things out. I can write 'using System.Drawing' without the system giving that line an error, which I thought was weird because it's nowhere to found in the references. I also really don't get it since I don't draw anything and don't think use anything from System.Drawing. Any time I reference the 'System' package I get this error, I can't go without because some android files rely on it. I've now lost hours now without any progress and basically am at the end of my road here.
Here's my MainActivity.cs file as it is now, narrowed down, it's my only .cs file:
using Android.Graphics;
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Gms.Maps;
using Android.Gms.Maps.Model;
using MySql.Data.MySqlClient;
using System;
namespace MapApp
{
[Activity(Label = "MapApp", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity, IOnMapReadyCallback
{
GoogleMap GMap;
/// database
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
}
private void SetUpMap()
{
if (GMap == null)
{
FragmentManager.FindFragmentById<MapFragment>(Resource.Id.googlemap).GetMapAsync(this);
}
}
public void OnMapReady(GoogleMap map)
{
GMap = map;
GMap.SetLatLngBoundsForCameraTarget(new LatLngBounds(
new LatLng(51.873176, 4.393930),
new LatLng(51.994576, 4.598036)));
GMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(51.917879,4.481134),13));
/*MarkerOptions markerOpt1 = new MarkerOptions();
markerOpt1.SetPosition(new LatLng(51.917879, 4.481134));
markerOpt1.SetTitle("Vimy Ridge");
GMap.AddMarker(markerOpt1);*/
CircleOptions dangerZone = new CircleOptions();
dangerZone.InvokeCenter(new LatLng(51.917879, 4.481134));
dangerZone.InvokeRadius(100);
dangerZone.InvokeFillColor(0x7F00FF00);
dangerZone.InvokeStrokeWidth(0);
GMap.AddCircle(dangerZone);
}
}
}
Here is a picture of my references and packages.(a lot of Xamarin packages in there because those were needed to load Google Maps):
Here another picture of my project structure as is, if it may help identify the problem.
I have tried to delete all my packages and clean my Big/Debug folder and rebuild everything but error still proceeds.
Everything worked perfectly and now I just can't build it anymore. I wrote "using System" once, got this error, and then never couldn't get rid of this error anymore.
I really do not want to restart my project for the second time, after getting getting unknown errors every hour so any help would GREATLY be appreciated.
Upvotes: 0
Views: 655
Reputation: 720
I have found the problem thanks to using Diagnostic logging. Turns out the 'MySql.Data' package loads 'System.Drawing' which of course is not supported in Xamarin.Android.
Dependency System.Drawing, Version=4.0.0.0, Culture=neutral,
Required by MySql.Data, Version=6.9.9.0, Culture=neutral
Thanks to Lexi Li for giving the one tip I exactly needed!
Upvotes: 3