Romano Roth
Romano Roth

Reputation: 21

monodroid exception while loading assemblies -> Could not load assembly System.Net

I've got a small assembly with some business-functionality (calling an webservice an reciving some data and give the data back in a list). This assembly was developed and compiled with visual studio.

I took the assembly and referenced this assembly with MonoDevelop and MonoTouch in an iPhone app project. It works perfectly.

Now I made a new project for a Android app in MonoDevelop with MonoDroid. The code compiles perfect. But when I want to deploy the app on the android I get this exception:

/Library/Frameworks/Mono.framework/External/xbuild/Novell/Novell.MonoDroid.Common.targets:
Error: Exception while loading assemblies: 
System.IO.FileNotFoundException: Could not load assembly 'System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. 
Perhaps it doesn't exist in the Mono for Android profile?
File name: 'System.Net.dll'
  at Monodroid.Tuner.MonoDroidResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0 
  at Monodroid.Tuner.MonoDroidResolver.Resolve (Mono.Cecil.AssemblyNameReference reference) [0x00000] in <filename unknown>:0 
  at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (System.Collections.Generic.List`1 assemblies, Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0 
  at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (System.Collections.Generic.List`1 assemblies, Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0 
  at Xamarin.Android.Tasks.ResolveAssemblies.Execute () [0x00000] in <filename unknown>:0 

As far as I know Mono has the System.Net assembly in the System assembly. I the System assembly is referenced in my project.

Any ideas?

Upvotes: 2

Views: 4165

Answers (1)

poupou
poupou

Reputation: 43553

As far as I know Mono has the System.Net Assembly in the System Assembly.

No. There is a System.Net namespace inside the System.dll assembly.

There is no System.Net.dll in MonoTouch and I don't think there's on in Mono for Android either (there was not last time I checked ;-)

There is a System.Net.dll in Silverlight. It contains WebClient, WebRequest, WebResponse... that are, in the regular framework (including MonoTouch and Mono for Android) part of System.dll.

The regular .NET framework has a System.Net.dll - but it's totally different from the one provided in Silverlight. That's confusing and was a very bad decision IMO.

I took the assembly and referenced this assembly with MonoDevelop and monotouch in an iPhone app project.

It may be working in MonoTouch when using the simulator because the JIT is being used (and missing references will be ignored as long as the code is not needed). However if you try to link your code (it's not linked by default) on the simulator or try to build for devices then I'm very confident you'll hit a similar error message (i.e. MonoTouch linker and/or AOT compiler will complain about the missing reference).

In short: you need to re-compile your source code against MonoTouch and Mono for Android SDK assemblies. That's the only safe way to ensure you won't be missing type references (or add assembly references that does not exists).

Upvotes: 4

Related Questions