I'm tring to wrap my c++ code to c# with using Swig. If the output destination of C# files is class library , there is no error and succesfully build.
However I want to support both windows phone 8.1 and windows 8.1 because of this reason I'm using portable class library rather than normal class library. In this situation I'm getting error that says;
The type or namespace name 'HandleRef' does not exist in the namespace 'System.Runtime.InteropServices' (are you missing an assembly reference?)
I really don't know what I am missing. What is the solution of this problem? My guess windows phone 8.1 and windows 8.1 does not support HandleRef but I'm not sure. If it so, What should I do?
This question is a bit older, but having had the same problem when using .NET Core I thought I'd share my Solution.
Change the imtype and csbody
To tell SWIG to stop using
HandleRefyou have to change the%typemap(imtype)and%typemap(csbody)of all default (or of specific) types.imtypespecifies the type that appears in yourmodulenamePINVOKEmethod parameters. Change it to something that can be marshaled from/to a pointer type.csbodyreplaces the entire body of yourSWIGTYPE_classes, meaning you'll have to implement you own (You have to, to change the variable that is stored asHandleRef). If your new implementation doesn't have agetCPtrmethod you have to change%typemap(csin)as wellHere is an example that uses
System.IntPtrinstead ofHandleRef, place it at the top in your interface file:Note:
SWIGTYPEis a placeholder for any type.Reference: SWIG 3.0 Documentation - Chapter 20 "SWIG and C#"