Windows Phone 7: All I get is System.MethodAccessException

自古美人都是妖i 提交于 2020-01-03 02:57:09

问题


This is my first time to develop apps in Windows Phone 7 and I was not that welcome. LOL.

Anyways, my problem is this MethodAccessException and am not sure why it keeps throwing me that exception.

Here's what I was trying to do.

  1. Getting Application StartUp Path by: System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase
    System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName
    API:
    [DllImport("coredll.dll", SetLastError = true)]
    public static extern int GetModuleFileName(IntPtr hModule, StringBuilder lpFilename, int nSize);

  2. Try to just enumerate some files
    int c = Directory.GetFiles(@"\").Length;
    System.Diagnostics.Debug.WriteLine("total files: " + c);

and am not sure what else since I just started coding. I have a big app in mind, and it will cover Registry IO, File IOs, and Database. But if this MethodAccessException keeps blocking my way, I'd rather be dead.

Am using Windows Phone 7.0
6176.WM7 RC1Escrow(buildlab).20100406 1457


回答1:


You cannot use Reflection or P/Invokes in Phone 7.

For File I/O you should be using IsolatedStorageFile for dealing with files. See this example (among many on the web).

There is no Registry access (maybe explaining why you think you need it can lead us to providing alternatives).

For Database access, there are lots of options. Depends on where you want the database (local/remote/cloud), what engine you want, ORM preferences, etc.



来源:https://stackoverflow.com/questions/7612550/windows-phone-7-all-i-get-is-system-methodaccessexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!