C# Windows Mobile 6 System.PlatformNotSupportedException

C# Windows Mobile 6 System.PlatformNotSupportedException,c#,compact-framework,windows-mobile-6,C#,Compact Framework,Windows Mobile 6,我编写了一个小型WM 6.1应用程序,可以读取和写入xml,但我遇到了以下异常: System.PlatformNotSupportedException was unhandled Message="PlatformNotSupportedException" StackTrace: at System.Globalization.CompareInfo..ctor(Int32 culture) at System.Globalization.Compare

我编写了一个小型WM 6.1应用程序,可以读取和写入xml,但我遇到了以下异常:

System.PlatformNotSupportedException was unhandled
  Message="PlatformNotSupportedException"
  StackTrace:
       at System.Globalization.CompareInfo..ctor(Int32 culture)
       at System.Globalization.CompareInfo.GetCompareInfo(Int32 culture)
       at System.Globalization.CultureInfo.get_CompareInfo()
       at System.CultureAwareComparer..ctor(CultureInfo culture, Boolean ignoreCase)
       at System.StringComparer.Create(CultureInfo culture, Boolean ignoreCase)
       at System.Data.DataTable.GetSpecialHashCode(String name)
       at System.Data.DataColumnCollection.RegisterColumnName(String name, DataColumn column, DataTable table)
       at System.Data.DataColumnCollection.BaseAdd(DataColumn column)
       at System.Data.DataColumnCollection.AddAt(Int32 index, DataColumn column)
       at System.Data.DataColumnCollection.Add(DataColumn column)
       at System.Data.DataColumnCollection.Add(String columnName, Type type)
       at MyApp.Settings.CreateDT(String Setting, String Key, String Value)
       at MyApp.Program.Main()
下面是CreatDT方法体:

public static DataTable CreateDT(string Setting, string Key, string Value)
        {
            DataTable dt;
            dt = new DataTable(Setting);
            dt.Columns.Add("Key", Type.GetType("System.String"));   //<-- error here
            dt.Columns.Add("Value", Type.GetType("System.String"));
            AddRow(ref dt, Key, Value);
            return dt;
        }
publicstaticdatatable CreateDT(字符串设置、字符串键、字符串值)
{
数据表dt;
dt=新数据表(设置);

dt.Columns.Add(“Key”,Type.GetType(“System.String”);//如果它是PlatformNotSupportedException,那么问题取决于系统中不存在的功能。可能缺少一些Compact Framework组件

您可以尝试选择下面标记的选项(不幸的是,图片上没有选择),看看是否有帮助

无论
Type.GetType(“System.String”)
是否会导致错误,我建议您在评论中使用Alex的
typeof(String)
建议

话虽如此,请尝试在有问题的例程周围放置一个临时的try…catch块,以获得更详细的错误消息

public static DataTable CreateDT(string Setting, string Key, string Value)
{
  DataTable dt = new DataTable(Setting);
  try {
    dt.Columns.Add("Key", typeof(String));   //<-- error here
    dt.Columns.Add("Value", typeof("String"));
    AddRow(ref dt, Key, Value);
  } catch (Exception err) {
    MessageBox.Show(err.Message);
    if (err.InnerException != null) {
      MessageBox.Show(err.InnerException.Message);
    }
  }
  return dt;
}
publicstaticdatatable CreateDT(字符串设置、字符串键、字符串值)
{
DataTable dt=新的DataTable(设置);
试一试{

dt.Columns.Add(“Key”,typeof(String));//尝试用
typeof(String)
替换
Type.GetType(“System.String”)
(我没有任何方法测试代码,只是猜测)。
typeof(String)
不起作用also@PawelZ此选项已选中