【发布时间】:2013-03-05 05:27:52
【问题描述】:
我已成功创建更新的 ZBar MonoTouch 绑定 dll,following up on this answer here from a while ago,使用更新的 [Field] 绑定来绑定静态 NSString(以前我只是在绑定 dll 中复制 NSString 的值)。
绑定 dll 编译良好(在发布模式下编译)。
并且使用我的应用程序中的绑定 ZBar.dll 在调试版本中工作正常,从本机库返回正确的 NSString 值。但是在 Release 版本中,它总是返回 null。
请注意,我已将链接器行为设置为剥离调试和发布版本的所有程序集,因此与链接器剥离任何内容无关。
我尝试为 Release 关闭 LLVM 编译器,但它在 Release 构建中仍然返回 null。然而,在 Release 版本中启用调试可以修复它(但显然不是解决方案)。
以下是绑定代码:
[Static]
interface ZBarSDK
{
// extern NSString* const ZBarReaderControllerResults;
[Field ("ZBarReaderControllerResults", "__Internal")]
NSString BarcodeResultsKey { get; }
}
这是反编译的 IL(根据 MonoDevelop):
namespace ZBar
{
public static class ZBarSDK
{
[CompilerGenerated]
private static NSString _BarcodeResultsKey;
[CompilerGenerated]
private static readonly IntPtr __Internal_libraryHandle = Dlfcn.dlopen(null, 0);
public static NSString BarcodeResultsKey
{
get
{
if (ZBarSDK._BarcodeResultsKey == null)
{
ZBarSDK._BarcodeResultsKey = Dlfcn.GetStringConstant(ZBarSDK.__Internal_libraryHandle, "ZBarReaderControllerResults");
}
return ZBarSDK._BarcodeResultsKey;
}
}
}
}
单点触控:6.0.10
【问题讨论】:
-
您确定需要 FieldAttribute 的“__Internal”第二个参数吗?
-
@StephaneDelcroix 是的,根据binding docs here (Field section):如果是静态链接,没有库可以绑定,所以需要使用__内部名称跨度>
-
@StephaneDelcroix 此外,启用调试模式时它确实有效。你会认为这样的事情会在所有情况下都破坏它。
标签: c# objective-c zbar-sdk xamarin.ios