I'm trying to create a project in .Net for IPhone using Monotouch. My problem is:
I have a DLL generated by Visual Studio 2010. This DLL just have an Interface and two other classes. I can use with no problems in my project in Visual Studio, but when I try to use the same one in Monotouch, i've got this error:
Building: HelloWorld (Debug|iPhoneSimulator) Building Solution HelloWorld Building: HelloWorld (Debug|iPhoneSimulator) Performing main compilation... Updating CodeBehind files Updated MainWindow.xib.designer.cs /Developer/MonoTouch/usr/bin/smcs /noconfig "/out:/Users/claudio/Documents/Development/DotNet/HelloWorld/HelloWorld/bin/iPhoneSimulator/Debug/HelloWorld.exe" "/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:/Developer/MonoTouch/usr/lib/mono/2.1/System.Runtime.Serialization.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.ServiceModel.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.ServiceModel.Web.dll" "/r:/Users/claudio/Documents/Development/DotNet/HelloWorld/HelloWorld/bin/Abcom.EmailService.ContractsCS.dll" /nologo /warn:4 /debug:+ /debug:full /optimize- /codepage:utf8 "/define:DEBUG" /t:exe "/Users/claudio/Documents/Development/DotNet/HelloWorld/HelloWorld/MainWindow.xib.designer.cs" "/Users/claudio/Documents/Development/DotNet/HelloWorld/HelloWorld/Main.cs" "/Users/claudio/Documents/Development/DotNet/HelloWorld/HelloWorld/Class1.cs" Missing method .ctor in assembly /Users/claudio/Documents/Development/DotNet/HelloWorld/HelloWorld/开发者_开发百科bin/Abcom.EmailService.ContractsCS.dll, type System.Runtime.Versioning.TargetFrameworkAttributeThe class System.Runtime.Versioning.TargetFrameworkAttribute could not be loaded, used in Abcom.EmailService.ContractsCSCan't find custom attr constructor image: /Users/claudio/Documents/Development/DotNet/HelloWorld/HelloWorld/bin/Abcom.EmailService.ContractsCS.dll mtoken: 0x0a000001 Unhandled Exception: System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'Abcom.EmailService.ContractsCS'. at (wrapper managed-to-native) System.Reflection.Assembly:InternalGetType (System.Reflection.Module,string,bool,bool) at System.Reflection.Assembly.GetType (System.String name, Boolean throwOnError, Boolean ignoreCase) [0x00000] in :0 at System.Reflection.Assembly.GetType (System.String name) [0x00000] in :0 at Mono.CSharp.RootNamespace.GetTypeInAssembly (System.Reflection.Assembly assembly, System.String name) [0x00000] in :0 at Mono.CSharp.RootNamespace.LookupTypeReflection (Mono.CSharp.CompilerContext ctx, System.String name, Location loc, Boolean must_be_unique) [0x00000] in :0 at Mono.CSharp.GlobalRootNamespace.LookupTypeReflection (Mono.CSharp.CompilerContext ctx, System.String name, Location loc, Boolean must_be_unique) [0x00000] in :0 at Mono.CSharp.Namespace.LookupType (Mono.CSharp.CompilerContext ctx, System.String name, Location loc) [0x00000] in :0 at Mono.CSharp.Namespace.Lookup (Mono.CSharp.CompilerContext ctx, System.String name, Location loc) [0x00000] in :0 at Mono.CSharp.TypeManager.CoreLookupType (Mono.CSharp.CompilerContext ctx, System.String ns_name, System.String name, Kind type_kind, Boolean required) [0x00000] in :0 at Mono.CSharp.TypeManager.InitCoreTypes (Mono.CSharp.CompilerContext ctx) [0x00000] in :0 at Mono.CSharp.Driver.Compile () [0x00000] in :0 at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in :0 Build complete -- 1 error, 0 warnings ---------------------- Done ---------------------- Build: 1 error, 0 warnings
Somebody knows what's going on here?
Regards, Claudio
Kevin is correct.
.NET has several "profiles" and the profiles are governed by their anchoring "mscorlib.dll". From the anchoring mscorlib.dll, all the rest of the assemblies flow. You will notice that you should not really mix an assembly compiled with a 2.0 mscorlib on a 4.0 system, or the other way around (they might work, but they are not guaranteed to work).
So in general, you need to compile your code using the same family of assemblies. When using the 4.0 mscorlib, you use the 4.0 family of assemblies; When using the 2.0, 3.5 and 3.5sp1, you use the 2.0 mscorlib; When you use Silverlight, you use the Silverlight 2.1 mscorlib set of APIs.
MonoTouch introduces its own anchoring mscorlib, versioned as 2.1.0.0 (the same one as Silverlight) and from this assembly, our API flows.
That is why you need to rebuild your libraries using Mono's assemblies for the 2.1.0.0 profile.
You can't link against DLLs compiled with Visual Studio. You have to recompile the DLL with Monotouch in order to use it.
精彩评论