MethodAccessException: Attempt to access the method failed. (Windows phone 7)
<p>I am working on a tool which reads the contents of an INI file. I am using kernel32 dll import in it. However, when I run the application on actual device, I get an exception like this, "MethodAccessException: Attempt to access the method failed." The device I am using is a Samsung Omnia (Windows Phone 7.1).</p>

<p>Apart from this in another app I am using core dll import and I am getting the same exception. How can this exception be removed?</p>

<pre><code>public class IniFile
{
    public string path;

    [DllImport("kernel32")]
    private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

    public IniFile(string INIPath)
    {
        path = INIPath;
    }

    public void IniWriteValue(string Section, string Key, string Value)
    {
        WritePrivateProfileString(Section, Key, Value, this.path);
    }

    public string IniReadValue(string Section, string Key)
    {
        StringBuilder temp = new StringBuilder(255);
        int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
        return temp.ToString();
    }
}
</code></pre>
