2009-08-15 41 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

相關問題