2012-12-05 38 views
1

我正在研究一個讀取INI文件內容的工具。我正在使用kernel32 dll導入。但是,當我在實際設備上運行應用程序時,我得到了這樣的異常,「MethodAccessException:嘗試訪問該方法失敗。」我使用的設備是三星Omnia(Windows Phone 7.1)。MethodAccessException:嘗試訪問該方法失敗。 (Windows phone 7)

除了這個在另一個應用程序中,我正在使用核心dll導入,我得到了同樣的異常。這個異常如何消除?

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(); 
    } 
} 

回答

相關問題