【问题标题】:Xamarin 'GetNSObject' does not exist in the namespace 'Internal.Runtime'命名空间“Internal.Runtime”中不存在 Xamarin“GetNSObject”
【发布时间】:2017-10-05 18:03:03
【问题描述】:

我们在 Mac 上的 Visual Studio 中包装原生 obj-c 库时遇到问题。 Build 在 NativeLibraryWrapperDef.cs 中为我们的类生成代码隐藏,但命名空间存在一些问题:

错误 CS0234:命名空间“Internal.Runtime”中不存在类型或命名空间名称“GetNSObject”(您是否缺少程序集引用?)(CS0234)(Gmc.Mobile.Sdk.iOS)

使用 Xamarin Studio 的同事可以很好地构建它。还有其他人遇到过这个问题吗?

using System;
using UIKit;
using Foundation;
using ObjCRuntime;
using Gmc.Mobile.Sdk;
using SafariServices;

namespace Internal.iOS
{
/*
 The first step to creating a binding is to add your native library ("libNativeLibrary.a")
 to the project by right-clicking (or Control-clicking) the folder containing this source
 file and clicking "Add files..." and then simply select the native library (or libraries)
 that you want to bind.

 When you do that, you'll notice that MonoDevelop generates a code-behind file for each
 native library which will contain a [LinkWith] attribute. MonoDevelop auto-detects the
 architectures that the native library supports and fills in that information for you,
 however, it cannot auto-detect any Frameworks or other system libraries that the
 native library may depend on, so you'll need to fill in that information yourself.

 Once you've done that, you're ready to move on to binding the API...


 Here is where you'd define your API definition for the native Objective-C library.

 For example, to bind the following Objective-C class:

     @interface Widget : NSObject {
     }

 The C# binding would look like this:

     [BaseType (typeof (NSObject))]
     interface Widget {
     }

 To bind Objective-C properties, such as:

     @property (nonatomic, readwrite, assign) CGPoint center;

 You would add a property definition in the C# interface like so:

     [Export ("center")]
     CGPoint Center { get; set; }

 To bind an Objective-C method, such as:

     -(void) doSomething:(NSObject *)object atIndex:(NSInteger)index;

 You would add a method definition to the C# interface like so:

     [Export ("doSomething:atIndex:")]
     void DoSomething (NSObject object, int index);

 Objective-C "constructors" such as:

     -(id)initWithElmo:(ElmoMuppet *)elmo;

 Can be bound as:

     [Export ("initWithElmo:")]
     IntPtr Constructor (ElmoMuppet elmo);

 For more information, see http://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/

*/

// @interface MRDCState : NSObject <MRDBObject>

[BaseType(typeof(NSObject))]
interface MRDCState : MRDBObject
{
    [Export ("remoteId", ArgumentSemantic.Copy)]
    string RemoteId { get; set; }

    [Export("documentID", ArgumentSemantic.Copy)]
    string DocumentID { get; set; }

    [Export("displayName", ArgumentSemantic.Copy)]
    string DisplayName { get; set; }

    [Export ("isUpdateAvailable", ArgumentSemantic.Copy)]
    bool IsUpdateAvailable { get; set;}

    [Export("lastUpdateDate", ArgumentSemantic.Copy)]
    NSDate LastUpdateDate { get; set; }

    [Export("content", ArgumentSemantic.Copy)]
    string Content { get; set; }

    //@property (nonatomic) int stateTypeFlag;
    [Export ("stateTypeFlag", ArgumentSemantic.Copy)]
    StateType TypeFlag { get; set; }
}

// @interface MRDCAppMessage : NSObject

[Protocol]
[BaseType(typeof(NSObject))]
interface MRAppMessage
{
    // @property NSUInteger messageID;
    [Export("messageID")]
    ulong MessageID { get; set; }

    // @property NSString *documentID;
    [Export("documentID")]
    string DocumentID { get; set; }

    // @property NSString *messageType;
    [Export("messageType")]
    string MessageType { get; set; }

    // @property NSString *payload;
    [Export("payload")]
    string Payload { get; set; }

    // - (instancetype)initWithID:(NSUInteger)messageID documentID:(NSString *)documentID type:(NSString *)messageType payload:(NSString *)payload;
    [Export("initWithID:documentID:messageType:payload:")]
    IntPtr Constructor(ulong messageID, string documentID, string messageType, string payload);
}

【问题讨论】:

  • 它在ObjCRuntime命名空间中:ObjCRuntime.Runtime.GetNSObject(),你能添加一个你的NativeLibraryWrapperDef.cs的样本吗...
  • 我添加了部分文件来提问。我只是试图从 Internal.iOS 命名空间中删除 Internal。现在库的包装器编译得很好。我不确定内部命名空间是从哪里来的。 (当我尝试在应用程序中使用新包装器 .dll 时会出现一些问题,但这可能是由其他原因引起的)

标签: c# binding xamarin.ios monodevelop code-behind


【解决方案1】:

从 Internal.iOS 命名空间中删除 internal 并使用协议和模型属性修复了一些问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    相关资源
    最近更新 更多