gpt4 book ai didi

C# 错误 : 'Class' is inaccessible due to protection level

转载 作者:行者123 更新时间:2023-11-30 15:12:25 24 4
gpt4 key购买 nike

我遇到此错误:“CLGDMFeed.Dal.DataManager”由于保护级别而无法访问。我不知道为什么我会得到这个。

这是我的类(class)。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CLGDMFeed.Bol;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;


namespace CLGDMFeed.Dal
{
public static class DataManager
{

#region Methods
public static void SerializeFeed(string sFileName, Feed feed)
{
try
{
using (Stream stream = File.Open(sFileName, FileMode.Create))
{
BinaryFormatter binform = new BinaryFormatter();
binform.Serialize(stream, feed);
stream.Close();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}

public static Feed DeSerializeFeed(string sFileName)
{
Feed feed;
try
{
using (Stream stream = File.Open(sFileName, FileMode.Open))
{
BinaryFormatter binform = new BinaryFormatter();
feed = (Feed)binform.Deserialize(stream);
stream.Close();
}
return feed;
}

catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}

public static void SerializeIListFeed(string sFileName, IList<Feed> list)
{
try
{
using (Stream stream = File.Open(sFileName, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(stream, list);
stream.Close();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}

public static IList<Feed> DeSerializeIListFeed(string sFileName)
{
IList<Feed> list;
try
{
using (Stream stream = File.Open(sFileName, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
list = (IList<Feed>)bf.Deserialize(stream);
stream.Close();
}
return list;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}





#endregion
}
}

这是我的表格

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CLGDMFeed.Dal;
using CLGDMFeed.Bol;


namespace ViewerGDMFeed
{
public partial class Viewer : Form
{
//Lijst van object Deserializeren van een bestand zodat je ermee kan werken
IList<Feed> ListFeeds = DataManager.DeSerializeIListFeed("C:\\Documents and Settings\\sam\\Bureaublad\\Listfeeds.lfds");

public Viewer()
{
InitializeComponent();

//De namen van de feeds toevoegen aan je combobox
foreach (Feed feed in ListFeeds)
{
comboBox.Items.Add(feed.STitle);
}

}

private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
//Overlopen welke feed uit je lijst overeenkomt met de gekozen feed uit combox
foreach (Feed feed in ListFeeds)
{

if (comboBox.SelectedText == feed.STitle)
{
//De labels invullen met de juiste data
ViewerLabelTitle.Text = feed.STitle;
//...
}
}
}

}
}

对不起所有的代码

有谁知道如何解决这个问题?谢谢


我重建了类库,错误消失了。

但是我有一个新错误:找不到元数据文件 'C:\Documents and Settings\sam\Bureaublad\Herexamen programmeren\WindowsFormsApplication1\CLGDMFeed\bin\Debug\CLGDMFeed.dll'

最佳答案

似乎你的项目中有一个无效的引用

关于C# 错误 : 'Class' is inaccessible due to protection level,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1282044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com