Ошибка при работе с XML - C#
Формулировка задачи:
Нужно данные с XML файла переместить в коллекцию. Вот сам XML файл
Вот класс сущности:
А вот метод для десериализации:
При запуске в строке
выскакивает исключение:
Подскажите в чём может быть дело?
<?xml version="1.0" encoding="UTF-8"?>
<User xmlns="urn:task-manager">
<users>
<Login>Superuser</Login>
<FirstName>Максим</FirstName>
<LastName>Аверкин</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2014-10-03T00:00:00</RegistrationDate>
<FullName>Максим Аверкин</FullName>
<Password>5f4dcc3b5aa765d61d8327deb882cf99</Password>
<Role>User</Role>
<Id>0d2da234-6b23-41db-b25a-3310add1d89a</Id>
</users>
<users>
<Login>LittlePonny</Login>
<FirstName>Ольга</FirstName>
<LastName>Нефедова</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2014-11-06T00:00:00</RegistrationDate>
<FullName>Ольга Нефедова</FullName>
<Password>25f9e794323b453885f5181f1b624d0b</Password>
<Role>User</Role>
<Id>c2b0bd56-65f9-4c26-a972-a17e52b7a461</Id>
</users>
<users>
<Login>Smuzy</Login>
<FirstName>Олег</FirstName>
<LastName>Смойлов</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2014-05-10T00:00:00</RegistrationDate>
<FullName>Олег Смойлов</FullName>
<Password>ee95a16d763ab0d26ee62c53056df928</Password>
<Role>User</Role>
<Id>3b411036-af57-413c-812c-6bee5c39ddac</Id>
</users>
<users>
<Login>Ragana</Login>
<FirstName>Кристина</FirstName>
<LastName>Вершинина</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2015-10-01T00:00:00</RegistrationDate>
<FullName>Кристина Вершинина</FullName>
<Password>673eb027e9c056f57140322807351dd5</Password>
<Role>User</Role>
<Id>0244be75-fc0e-456e-9471-2846ed05736d</Id>
</users>
<users>
<Login>Akakiy</Login>
<FirstName>Игорь</FirstName>
<LastName>Кривицкий</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2015-02-20T00:00:00</RegistrationDate>
<FullName>Игорь Кривицкий</FullName>
<Password>cb1d3a6249c2d223c620393fa6420868</Password>
<Role>User</Role>
<Id>dd073703-68ef-4b3a-bd70-d4a19a87e8e1</Id>
</users>
<users>
<Login>Lary</Login>
<FirstName>Сергей</FirstName>
<LastName>Микулич</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2015-01-03T00:00:00</RegistrationDate>
<FullName>Сергей Микулич</FullName>
<Password>6ab3d0526bb1d023ab7c4fee4fb684df</Password>
<Role>User</Role>
<Id>10f387d8-3671-40dd-a4f8-999ff3975ddb</Id>
</users>
<users>
<Login>Grazyy</Login>
<FirstName>Виталий</FirstName>
<LastName>Евтухов</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2015-04-24T00:00:00</RegistrationDate>
<FullName>Виталий Евтухов</FullName>
<Password>a77224c90dc6867f603a3afd92767598</Password>
<Role>User</Role>
<Id>07eb366f-3918-4e52-8ebb-2407a1f96390</Id>
</users>
<users>
<Login>Bigboss</Login>
<FirstName>Валерий</FirstName>
<LastName>Маковецкий</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2014-03-08T00:00:00</RegistrationDate>
<FullName>Валерий Маковецкий</FullName>
<Password>d8578edf8458ce06fbc5bb76a58c5ca4</Password>
<Role>User</Role>
<Id>51c2844b-938c-4ba1-b50a-af6dea8a765d</Id>
</users>
<users>
<Login>Administrator</Login>
<FirstName>Константин</FirstName>
<LastName>Горбачёв</LastName>
<Locale>ru</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2014-01-02T00:00:00</RegistrationDate>
<FullName>Константин Горбачёв</FullName>
<Password>21232f297a57a5a743894a0e4a801fc3</Password>
<Role>Admin</Role>
<Id>5fca13d8-91d6-4023-b60a-d9334ec5c983</Id>
</users>
<users>
<Login>Login</Login>
<FirstName>FirstName</FirstName>
<LastName>LastName</LastName>
<Locale>ru</Locale>
<TimeZone>Paraguay Standard Time</TimeZone>
<RegistrationDate>2015-05-19T14:35:33</RegistrationDate>
<FullName>FirstName LastName</FullName>
<Password>50f3fca4c6134bd001fdfe3159686be9</Password>
<Role>User</Role>
<Id>36fb1c67-7363-4cae-a8f9-7b0a9bcdfb3e</Id>
</users>
<users>
<Login>Vinny</Login>
<FirstName>Владимир</FirstName>
<LastName>Некрасов</LastName>
<Locale>en</Locale>
<TimeZone>E. Europe Standard Time</TimeZone>
<RegistrationDate>2014-12-15T00:00:00</RegistrationDate>
<FullName>Владимир Некрасов</FullName>
<Password>1897a69ef451f0991bb85c6e7c35aa31</Password>
<Role>User</Role>
<Id>0ee509d6-8c7d-4070-98dd-9003cb266496</Id>
</users>
</User>
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaskManager.DAL;
namespace TaskManager.DAL.Entities
{
[Serializable]
public class User : IEntity
{
public string Login { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Locale { get; set; }
public string TimeZone { get; set; }
public DateTime RegistrationDate { get; set; }
//public string FullName
//{
// get { return string.Format("{0} {1}", FirstName, LastName); }
//}
public string Password { get; set; }
public string Role { get; set; }
}
}public List<T> GetAll<T>(string path, string pathxsd)
{
logger.Trace("Sample trace message");
logger.Debug("Sample debug message");
logger.Info("Sample informational message");
logger.Warn("Sample warning message");
logger.Error("Sample error message");
logger.Fatal("Sample fatal error message");
// bool result = DtdValidation(path);
bool resultxsd = XsdValidation(path, pathxsd);
XmlSerializer serializer = new XmlSerializer(typeof(T));
List<T> list = new List<T>();
object locker = new object();
if (resultxsd == true)
{
using (FileStream stream = File.OpenRead(path))
{
list = (List<T>) serializer.Deserialize(stream);
}
}
return list;
}list = (List<T>) serializer.Deserialize(stream);
Исключение типа "System.InvalidOperationException" возникло в System.Xml.dll, но не было обработано в коде пользователя
Дополнительные сведения: В документе XML (2, 2) присутствует ошибка.
Решение задачи: «Ошибка при работе с XML»
textual
Листинг программы
<?xml version="1.0" encoding="UTF-8"?> <Users xmlns="urn:task-manager"> <User> <Login>Superuser</Login> <FirstName>Максим</FirstName> <LastName>Аверкин</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2014-10-03T00:00:00</RegistrationDate> <FullName>Максим Аверкин</FullName> <Password>5f4dcc3b5aa765d61d8327deb882cf99</Password> <Role>User</Role> <Id>0d2da234-6b23-41db-b25a-3310add1d89a</Id> </User> <User> <Login>LittlePonny</Login> <FirstName>Ольга</FirstName> <LastName>Нефедова</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2014-11-06T00:00:00</RegistrationDate> <FullName>Ольга Нефедова</FullName> <Password>25f9e794323b453885f5181f1b624d0b</Password> <Role>User</Role> <Id>c2b0bd56-65f9-4c26-a972-a17e52b7a461</Id> </User> <User> <Login>Smuzy</Login> <FirstName>Олег</FirstName> <LastName>Смойлов</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2014-05-10T00:00:00</RegistrationDate> <FullName>Олег Смойлов</FullName> <Password>ee95a16d763ab0d26ee62c53056df928</Password> <Role>User</Role> <Id>3b411036-af57-413c-812c-6bee5c39ddac</Id> </User> <User> <Login>Ragana</Login> <FirstName>Кристина</FirstName> <LastName>Вершинина</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2015-10-01T00:00:00</RegistrationDate> <FullName>Кристина Вершинина</FullName> <Password>673eb027e9c056f57140322807351dd5</Password> <Role>User</Role> <Id>0244be75-fc0e-456e-9471-2846ed05736d</Id> </User> <User> <Login>Akakiy</Login> <FirstName>Игорь</FirstName> <LastName>Кривицкий</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2015-02-20T00:00:00</RegistrationDate> <FullName>Игорь Кривицкий</FullName> <Password>cb1d3a6249c2d223c620393fa6420868</Password> <Role>User</Role> <Id>dd073703-68ef-4b3a-bd70-d4a19a87e8e1</Id> </User> <User> <Login>Lary</Login> <FirstName>Сергей</FirstName> <LastName>Микулич</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2015-01-03T00:00:00</RegistrationDate> <FullName>Сергей Микулич</FullName> <Password>6ab3d0526bb1d023ab7c4fee4fb684df</Password> <Role>User</Role> <Id>10f387d8-3671-40dd-a4f8-999ff3975ddb</Id> </User> <User> <Login>Grazyy</Login> <FirstName>Виталий</FirstName> <LastName>Евтухов</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2015-04-24T00:00:00</RegistrationDate> <FullName>Виталий Евтухов</FullName> <Password>a77224c90dc6867f603a3afd92767598</Password> <Role>User</Role> <Id>07eb366f-3918-4e52-8ebb-2407a1f96390</Id> </User> <User> <Login>Bigboss</Login> <FirstName>Валерий</FirstName> <LastName>Маковецкий</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2014-03-08T00:00:00</RegistrationDate> <FullName>Валерий Маковецкий</FullName> <Password>d8578edf8458ce06fbc5bb76a58c5ca4</Password> <Role>User</Role> <Id>51c2844b-938c-4ba1-b50a-af6dea8a765d</Id> </User> <User> <Login>Administrator</Login> <FirstName>Константин</FirstName> <LastName>Горбачёв</LastName> <Locale>ru</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2014-01-02T00:00:00</RegistrationDate> <FullName>Константин Горбачёв</FullName> <Password>21232f297a57a5a743894a0e4a801fc3</Password> <Role>Admin</Role> <Id>5fca13d8-91d6-4023-b60a-d9334ec5c983</Id> </User> <User> <Login>Login</Login> <FirstName>FirstName</FirstName> <LastName>LastName</LastName> <Locale>ru</Locale> <TimeZone>Paraguay Standard Time</TimeZone> <RegistrationDate>2015-05-19T14:35:33</RegistrationDate> <FullName>FirstName LastName</FullName> <Password>50f3fca4c6134bd001fdfe3159686be9</Password> <Role>User</Role> <Id>36fb1c67-7363-4cae-a8f9-7b0a9bcdfb3e</Id> </User> <User> <Login>Vinny</Login> <FirstName>Владимир</FirstName> <LastName>Некрасов</LastName> <Locale>en</Locale> <TimeZone>E. Europe Standard Time</TimeZone> <RegistrationDate>2014-12-15T00:00:00</RegistrationDate> <FullName>Владимир Некрасов</FullName> <Password>1897a69ef451f0991bb85c6e7c35aa31</Password> <Role>User</Role> <Id>0ee509d6-8c7d-4070-98dd-9003cb266496</Id> </User> </Users>