小编The*_*Man的帖子

System.TypeAccessException:尝试通过方法“X”访问类型“Y”失败

好的,我已经用谷歌搜索了将近两天,并且尝试了几乎所有与此错误相关的 SO 解决方案,但没有任何效果。大多数有关此问题的问题是关于 Click-once 应用程序、JSON、Web 应用程序等的安全设置。但对于普通的旧 Winforms 应用程序则没有任何问题。

这是完整的错误

System.TypeAccessException:尝试通过方法“Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSystemSetup.Write3_SystemSetup(System.Object)”访问类型“DataFacture.Common.Globals+SystemSetup”失败。在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSystemSetup.Write3_SystemSetup(Object o)

这是“SystemSetup”类的简化版本

public class SystemSetup
    {
        private string machineId, windowsVersion;

        public SystemSetup() { }
        public SystemSetup(string machineId, string windowsVersion)
        {
            this.machineId = machineId;
            this.windowsVersion = windowsVersion
        }

        public string MachineID { get { return machineId; } set { machineId = value; } }
        public string WindowsVersion{ get { return windowsVersion; } set { windowsVersion= value; } }
    }
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试使用以下代码和“writer.Serialize(wfile, objectSerializer);”生成 SystemSetup 对象的 XML 行,发生错误

public static void WriteXML(Object objectSerializer, …
Run Code Online (Sandbox Code Playgroud)

.net c# xml winforms

2
推荐指数
1
解决办法
8883
查看次数

标签 统计

.net ×1

c# ×1

winforms ×1

xml ×1