C # error: Class is unavailable due to protection level

I have this error: "CLGDMFeed.Dal.DataManager" is unavailable due to the level of protection. And I have no idea why I understand this.

This is my 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
    }
}

This is my form

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;
                    //...
                }
            }
        }

    }
}

Sorry for all the code.

Does anyone know how to solve this problem? Thanks


I restored the classliberary and the error went away.

But I have a new error: the metadata file 'C: \ Documents and Settings \ sam \ Bureaublad \ Herexamen programmeren \ WindowsFormsApplication1 \ CLGDMFeed \ bin \ Debug \ CLGDMFeed.dll' was not found.

+3
source share
4 answers

it looks like you have an invalid link in your project

+2
source

! . GetObjectData. Stil , . .

+2

The code looks fine, so you're probably not using the version of the file that you think you are. Check and open from Solution-Explorer.

+1
source

Verify that the assembly with the Dal namespace has been signed with a strong name. Sometimes unsigned assemblies can cause such problems.

0
source

Source: https://habr.com/ru/post/1715236/


All Articles