3

I'm currently building a MonoTouch app, and want to share as much code as possible between it and any other future platforms. I figured the best way would be to use a PCL for the common code.

Problem goes that when I try and reference System.Collection.Generic.List<T> in my PCL library, MOnoDevelop highlights the List text in red (as if to say the reference can't be found), but when I build the project, the compiler has no problems and builds it normally...

For instance, I can have the following code in my PCL

MonoDevelop highlighting incorrect resolve errors

and MD will compile this just fine, and this method can be consumed from my MT app.

However it's frustrating to work with as it's misleading me along the way into thinking that code which should compile won't, and I'm missing a lot of the benefits of IntelliSense.

I've tried the solution listed about switching the compiler, but that hasn't helped. Hope someone has suggestions on how to fix this?

For interests sake, here's what intellisense gives me for the System.Collections.Generic namespace (there's one item out of view in that list - Stack<T>)

IntelliSense listing of System.Collections.Generic in MonoDevelop with PCL project

Should also mention that i'm using MonoDevelop v3.0.5, Mono v2.10.9, MT v6.0.6

Community
  • 1
  • 1
Xerxes
  • 309
  • 3
  • 12
  • Is `mscorlib` referenced in MonoDevelop? I know the compiler and VS implicitly creates a reference for it. – leppie Dec 06 '12 at 10:24
  • @leppie the only references shown are to System, System.Core, System.Xml and all 3 have the following error: Assembly not available for .NETPortable 4.0 Profile1 profile (in Mono 2.10.9) – Xerxes Dec 06 '12 at 11:01
  • `Stack` lives in System.dll. Can you forcefully try add a reference to `mscorlib`? – leppie Dec 06 '12 at 11:03
  • Added the ref, but didn't help. Even if that did work it wouldn't help because, that would be a ref to the 4.0 full profile not the PCL, am I right? – Xerxes Dec 06 '12 at 11:09
  • Sorry - strike the first part of my previous comment out. Adding the ref to mscorlib in fact did work (i needed to restart MD to get it to kick-in). Either way though, doesn't linking against mscorlib 4.0 defeat the purpose of using a PCL? – Xerxes Dec 06 '12 at 11:14
  • It is not static linking, so it should use the PCL's mscorlib at runtime :) – leppie Dec 06 '12 at 11:15

1 Answers1

3

MonoDevelop 3.x's support for Portable Class Libraries is a hack on Linux and Mac since on those platforms, there aren't any PCL assemblies (Mono doesn't have any PCL assemblies).

When MonoDevelop compiles a PCL project on Mac or Linux (where real PCL assemblies aren't available), it uses a hacked Microsoft.Portable.CSharp.targets file to reference MonoTouch or Mono4Android assemblies (if available), otherwise it falls back to compiling against the .NET 4.0 assemblies.

The specific problem you are seeing is caused by MonoDevelop not being able to find the true PCL mscorlib/System/etc PCL assemblies on your system.

jstedfast
  • 35,744
  • 5
  • 97
  • 110