2009-08-15 40 views
3

我出现此错误:由于保护级别原因'CLGDMFeed.Dal.DataManager'无法访问。 我不知道为什么我得到这个。C#错误:由于保护级别而无法访问'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; 
        //... 
       } 
      } 
     } 

    } 
} 

对不起,所有的代码

有谁硝酸钾如何解决那朵问题? 感谢


我有重建classliberary和错误消失。

但我有一个新的错误:元数据文件 'C:\ Documents和Settings \ SAM \ Bureaublad \ Herexamen programmeren \ WindowsFormsApplication1 \ CLGDMFeed \ BIN \调试\ CLGDMFeed.dll' 无法找到

+0

当您编译此代码时,是否会收到其他错误或警告? – Grzenio 2009-08-15 15:00:40

+0

您是否更新课程,然后忘记将它复制到您正在运行它的位置? – 2009-08-15 15:01:23

+0

Grzenio,是的,我有一个其他错误: 'CLGDMFeed.Bol.FeedItem' 不实现接口成员“System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext) ' Paul,你是什么意思的更新和复制? – samuhe 2009-08-15 15:22:57

回答

2

好像你在你的项目中

1

代码看起来没问题,所以你可能没有运行你认为你的文件的版本。从Solution-Explorer中检查并打开。

+0

这可能是问题所在,因为我还在WindowsForm中添加了一个新按钮,但是当我运行它时,您看不到它。 我重新启动Visual Studio,但我仍然有相同的错误,我仍然看不到按钮。 – samuhe 2009-08-15 15:18:01

+0

是的,重建dal(假设它是一个不同的项目)。检查你的参考是否是新建版本。 – 2009-08-15 15:23:46

+0

复制/移动文件后,事情会变得混乱。解决方案资源管理器是您理智的锚点。学会使用它。 – 2009-08-15 15:48:22

2

发现问题的无效参考!有一种方法缺失。 GetObjectData使用。 Stil没有得到元数据文件问题的来源。 thanx很多为您的答案。 Greetings

+0

请_编辑问题而不是发布答案。 – 2009-08-17 18:18:59

+2

鼓励回答你自己的问题。 http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ – mikek3332002 2011-09-29 01:23:06

+0

如果你纠正一个问题,然后它不再是一个“问题”和/或不再说明问题。要提供自己的答案一样,这是正确的 – 2016-06-06 01:41:14

0

确保带有Dal名称空间的程序集已使用强名称密钥进行了签名。有时未签名的程序集可能会导致类似的问题。

+0

评论为什么-1,将不胜感激。我通过签署目标程序集解决了一个案例。没有采取其他行动。 – Alexey 2010-09-12 19:26:11

相关问题