Ang*_*ker 9 c# serialization exception .net-3.5 c#-3.0
我有以下代码:
class Program
{
static void Main(string[] args)
{
string xml = @"<ArrayOfUserSetting>
<UserSetting>
<Value>Proposals</Value>
<Name>LastGroup</Name>
</UserSetting>
<UserSetting>
<Value>Visible</Value>
<Name>WidgetsVisibility</Name>
</UserSetting>
</ArrayOfUserSetting>";
List<UserSetting> settings =
GetObjFromXmlDocument<List<UserSetting>>(xml);
}
public static T GetObjFromXmlDocument<T>(string xml)
{
T customType;
XmlSerializer serializer = new XmlSerializer(typeof(T));
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xml);
using (XmlNodeReader xmlNodeReader = new XmlNodeReader(xmlDocument))
{
customType = (T)serializer.Deserialize(xmlNodeReader);
}
return customType;
}
}
[Serializable]
public class UserSetting
{
public string Value { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
代码工作正常,对GetObjFromXmlDocument的调用产生一个List集合.但是,执行时,我总是System.IO.FileNotFoundException在mscorlib.dll中获得第一次机会异常XmlSerializer serializer = new XmlSerializer(typeof(T));.
所以我进入了Debug/Exception并打开了Managed Debugging Assistants.我在这一行得到了以下内容:
显示名称为"mscorlib.XmlSerializers"的程序集无法加载到ID为1的AppDomain的"LoadFrom"绑定上下文中.失败的原因是:System.IO.FileNotFoundException:无法加载文件或程序集'mscorlib.XmlSerializers ,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'或其依赖项之一.该系统找不到指定的文件.文件名:'mscorlib.XmlSerializers,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'
有人可以解释为什么会这样吗?我能为UserSetting课堂做些什么让问题消失吗?该应用程序对性能非常敏感,我宁愿没有例外.
| 归档时间: |
|
| 查看次数: |
7143 次 |
| 最近记录: |