我收到System.Windows.Forms.dll中出现的'System.TypeLoadException'。这是错误消息的其余部分。
其他信息:无法从程序集'DataTeamMailerCSharp,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'加载类型'DataTeamMailerCSharp.NewReport',因为方法'.ctor'没有实现(没有RVA)。< / p>
这是正在发生的课程。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DataTeamMailerCSharp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainGUI());
}
}
}
此处发生错误:
Application.Run(new mainGUI());
在回复评论时,我最近在我的一个课程中改变了这一点。我正在尝试XML序列化,并且在无参数构造函数中它告诉我它需要一个body或exter,partial和其他东西。这是类代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataTeamMailerCSharp
{
[Serializable] class NewPerson
{
public string personName { get; set; }
public string personEmail { get; set; }
public string personReports { get; set; }
public NewPerson(string name, string email, string reports)
{
personName = name;
personEmail = email;
personReports = reports;
}
private extern NewPerson();
}
}
现在可能是private extern NewPerson();
造成这种情况吗?
答案 0 :(得分:5)
使用XmlSerializer
序列化/反序列化时,需要一个公共的无参数默认构造函数。添加一个...
namespace DataTeamMailerCSharp
{
[Serializable]
public class NewPerson
{
public string personName { get; set; }
public string personEmail { get; set; }
public string personReports { get; set; }
public NewPerson(string name, string email, string reports)
{
personName = name;
personEmail = email;
personReports = reports;
}
public NewPerson() { } // for serialization
// private extern NewPerson(); -- not needed
}
}