Xamarin: Binding ios protocol / delegate cannot access enumeration defined in structs.cs

I am currently creating ios bindings for the EDQueue library .

The Structs.cs file looks something like this:

 using System; using ObjCRuntime; namespace EDQueue { // => Enums attributed with[NativeAttribute] must have an underlying type of `long` or `ulong` [Native] public enum EDQueueResult : long { Success = 0, Fail, Critical } } 

The ApiDefinition.cs file looks something like this:

 using System; using Foundation; using ObjCRuntime; namespace EDQueue { // typedef void (^EDQueueCompletionBlock)(EDQueueResult); delegate void EDQueueCompletionBlock(EDQueueResult result); // ETC.... // @protocol EDQueueDelegate <NSObject> [Protocol, Model] [BaseType(typeof(NSObject))] interface EDQueueDelegate { // @optional -(EDQueueResult)queue:(EDQueue *)queue processJob:(NSDictionary *)job; [Export("queue:processJob:")] EDQueueResult Queue(EDQueue queue, NSDictionary job); //// @optional -(void)queue:(EDQueue *)queue processJob:(NSDictionary *)job completion:(EDQueueCompletionBlock)block; //[Export("queue:processJob:completion:")] //void Queue(EDQueue queue, NSDictionary job, EDQueueCompletionBlock completeBlock); } // ETC... } 

As written, the following error occurs: Error CS0426: the type name "EDQueueResult" does not exist in the type "EDQueue" (CS0426) (EDQueue) in the file EDQueueDelegate.g.cs

This file looks like this when an error occurs:

 // // Auto-generated from generator.cs, do not edit // // We keep references to objects, so warning 414 is expected #pragma warning disable 414 using System; using System.Drawing; using System.Diagnostics; using System.ComponentModel; using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using UIKit; using GLKit; using Metal; using MapKit; using ModelIO; using SceneKit; using Security; using AudioUnit; using CoreVideo; using CoreMedia; using QuickLook; using Foundation; using CoreMotion; using ObjCRuntime; using AddressBook; using CoreGraphics; using CoreLocation; using AVFoundation; using NewsstandKit; using CoreAnimation; using CoreFoundation; namespace EDQueue { [Protocol (Name = "EDQueueDelegate", WrapperType = typeof (EDQueueDelegateWrapper))] [ProtocolMember (IsRequired = false, IsProperty = false, IsStatic = false, Name = "Queue", Selector = "queue:processJob:", ReturnType = typeof (EDQueue.EDQueueResult), ParameterType = new Type [] { typeof (global::EDQueue.EDQueue), typeof (NSDictionary) }, ParameterByRef = new bool [] { false, false })] public interface IEDQueueDelegate : INativeObject, IDisposable { } // ETC... } 

However, if I delete or comment on the [Protocol, Model] bit, the library builds without errors.

I also get a similar error if I uncomment the second function using EDQueueCompletionBlock , which ultimately relies on an EDQueueResult enumeration.

The assembly action of the Structs.cs file Structs.cs set to ObjcBindingCoreSource .

Any help really appreciated. Thanks!

+5
source share
1 answer

Since you have an EDQueue namespace and a type (interface) named EDQueue - you cannot reference any type in the EDQueue namespace with EDQueue.TypeName , so this statement:

 ReturnType = typeof (EDQueue.EDQueueResult) 

It does not compile because the compiler will look for an element inside the EDQueue interface (even if the interfaces cannot have child classes, as well as static members), and not inside the EDQueue namespace.

The most obvious way to fix this is to never have a namespace and enter the name of the same name, so rename either the namespace or the type name.

If this is not possible or you are not entirely sure that it will not have side effects - change the link to

 ReturnType = typeof (EDQueueResult) 

and add using EDQueue to the block. Alternatively, link like this:

 ReturnType = typeof (global::EDQueue.EDQueueResult) 
+1
source

All Articles