2009-08-15 26 views
3

Iこのエラーが発生しました:保護レベルのために 'CLGDMFeed.Dal.DataManager'にアクセスできません。 そして、なぜ私はこれを得るアイデアがありません。C#エラー:保護レベルのため 'Class'にアクセスできません

Tisは私のクラスです。

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

    } 
} 

すべてのコード

のため申し訳ありませんが、誰もがTISの問題を解決する方法自演ん私のフォームですか? おかげ


私はclassliberaryを再構築しており、エラーがなくなっています。メタデータファイル 'C:\ DocumentsとSettings \ SAM \ Bureaublad \ Herexamen programmeren \ WindowsFormsApplication1 \ CLGDMFeed binに\デバッグ\ CLGDMFeed.dll \' を

+0

このコードをコンパイルするときに、他のエラーや警告が表示されますか? – Grzenio

+0

クラスを更新して、それを実行している場所に偶然にコピーすることを忘れましたか? –

+0

Grzenio、はい他のエラーがあります。 'CLGDMFeed.Bol.FeedItem'は、インターフェイスメンバー 'System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo、System.Runtime.Serialization.StreamingContext)を実装していません。 ' Paul、更新とコピーはどういう意味ですか? – samuhe

答えて

2

あなたのプロジェクトに無効な参照があるようです。

1

コードを見つけることができませんでした

は、しかし、私は新しいエラーを持っていますOKと思われるので、あなたが思っているファイルのバージョンを実行していない可能性があります。ソリューションエクスプローラから確認して開きます。

+0

私はWindowsフォームに新しいボタンを追加したのでこれが問題になるかもしれませんが、実行すると表示されません。 Visual Studioを再起動しましたが、同じエラーが表示されますが、まだボタンは表示されません。 – samuhe

+0

はい、dalを再構築します(別のプロジェクトだとします)。参照が新しく構築されたバージョンであることを確認してください。 –

+0

ファイルのコピー/移動後に混乱することがあります。あなたの正気のアンカーはソリューションエクスプローラです。それを使用する方法を学ぶ。 –

2

問題が見つかりました。方法がありませんでした。 GetObjectData。 Stilは、メタデータファイルの問題の原因となっていません。あなたの答えにはたくさんのことがあります。 グリーティング

+0

答えを投稿するのではなく、質問を編集してください。 –

+2

あなた自身の質問に答えることをお勧めします。 http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ – mikek3332002

+0

質問を修正すると、それはもはや「質問」ではなく、かつ/またはもはや問題を説明しません。このようにあなた自身の答えを提供するには、正しいことが –

0

Dal名前空間を持つアセンブリが強力な名前キーで署名されていることを確認してください。署名されていないアセンブリでは、そのような問題が発生することがあります。

+0

なぜ-1が評価されるのでしょうか。ターゲットアセンブリに署名して解決したケースがありました。他に何もしなかった。 – Alexey

関連する問題