I am trying to develop a native plugin for Unity (using Unity 2017.1.0f3 and VS 2015). The target platform for my native plugin is UWP and the plugin is written in C#.
Below are the code for my plugin and my script in Unity.
Plugin code in a Class Library targeting Windows 10 14393
public static class SettingsService
{
public static string GetSetting( string key )
{
var localSettings = ApplicationData.Current.LocalSettings;
try
{
var stringvalue = localSettings.Values[key] as string;
return stringvalue;
}
catch ( ArgumentNullException en )
{
return default( string );
}
}
public static void SaveSetting( string key, string value )
{
var localSettings = ApplicationData.Current.LocalSettings;
localSettings.Values[key] = value;
}
}
Unity script code
public class TestNativePlugin : MonoBehaviour {
[DllImport( "UnityPluginTestUWP", EntryPoint = "GetSetting" )]
private static extern string GetSetting( string key );
[DllImport( "UnityPluginTestUWP", EntryPoint = "SaveSetting" )]
private static extern void SaveSetting( string key, string value );
// Use this for initialization
void Start () {
SaveSetting( "setting", "oeoeoe" );
System.Diagnostics.Debug.WriteLine( GetSetting( "setting" ) );
}
}
The problem is that in runtime I get an EntryPointNotFoundException with the message :
Unable to find an entry point named 'SaveSetting' in DLL UnityPluginTestUWP.dll'
I have read online that this may occur because of mangling of function names by the compiler. But this was only in C++ code. My plugin is written in C#.
Any help to overcome this is welcome.