Okay, this is the code:
My Plugin Class:
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using System.Collections.Generic;
using System.Collections;
[assembly: ExtensionApplication(typeof(AutoCAD_BE.MyPlugin))]
[assembly: CommandClass(typeof(AutoCAD_BE.MyPlugin))]
namespace AutoCAD_BE
{
public class MyPlugin : IExtensionApplication
{
[CommandMethod("loadbe")]
public void LoadBe()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
Datenbank datenbank = new Datenbank(doc, db, tr);
Window1 window = new Window1(datenbank);
Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessWindow(window);
}
}
This is my Window Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Autodesk.AutoCAD.DatabaseServices;
namespace AutoCAD_BE
{
public partial class Window1 : System.Windows.Window
{
Datenbank datenbank;
public Window1(Datenbank datenbank)
{
this.datenbank = datenbank;
InitializeComponent();
}
// fills the listBox in the UI with blocknames
public void fillList(List<String> blockList)
{
foreach (String s in blockList)
{
listBlocks.Items.Add(s.ToString());
}
}
// fills the attribute-editting form with the attributes of the in the listbox selected block
private void listBlocks_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
datenbank.setBlockAttributes(listBlocks.SelectedItem.ToString());
AttributeDefinition tAttDef = datenbank.getAttributeDefinition();
tbRotation.Text = tAttDef.Layer;
tbLayer.Text = tAttDef.Layer;
tbEinfuegepunktX.Text = tAttDef.Position.X.ToString();
tbEinfuegepunktY.Text = tAttDef.Position.Y.ToString();
tbEinfuegepunktZ.Text = tAttDef.Position.Z.ToString();
}
//calls the fillList-method with the in the class datenbank generated blockList
private void Window_Loaded(object sender, RoutedEventArgs e)
{
fillList(datenbank.getBlockTableRecordNames());
}
}
}
and this is my Class whitch holds the Transactions with the database:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
namespace AutoCAD_BE
{
public class Datenbank
{
Database db;
Transaction tr;
Document doc;
AttributeDefinition AttDef;
List<String> BlockList = new List<String>();
public Datenbank(Document doc, Database db, Transaction tr)
{
this.doc = doc;
this.db = db;
this.tr = tr;
setBlockTableRecordNames();
}
//Gets the Blocktablerecordnames out of the blocktable and adds them into a list.
public void setBlockTableRecordNames()
{
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId objId in bt)
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(objId, OpenMode.ForRead);
BlockList.Add(btr.Name);
}
}
}
public List<String> getBlockTableRecordNames()
{
return (BlockList);
}
//Gets the AttributeDefinitions out of the BlocktableRecord
public void setBlockAttributes(String blockname)
{
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId objId in bt)
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(objId, OpenMode.ForRead);
if (btr.Name == blockname)
{
foreach (ObjectId tObjID in btr)
{
if ((tObjID.IsValid) && (!tObjID.IsErased) && (tObjID.ObjectClass.DxfName.ToUpper() == "ATTDEF"))
{
AttributeDefinition tAttDef = (AttributeDefinition)tr.GetObject(tObjID, OpenMode.ForRead);
setAttributeDefinition(tAttDef);
}
}
}
}
}
}
public void setAttributeDefinition(AttributeDefinition tAttDef)
{
AttDef = tAttDef;
}
public AttributeDefinition getAttributeDefinition()
{
return AttDef;
}
public void refreshBlockList(Transaction tr, Database db)
{
this.tr = tr;
this.db = db;
getBlockTableRecordNames();
}
}
}
Attached, you find a screenshot of the error and the whole "solution". 
What I want to do:
MyPlugin.cs gives the Document, Database and Transaction to Datenbank.cs.
Datenbank.cs gets the Blocktablerecordnames, my WPF-Window Window1.xaml is loaded and gets the datenbank.cs. In the Window1.xaml, the blocktablerecordnames are shown in a listbox, the user selects one and the setBlockAttributes-method in datenbank.cs is called. The datenbank.cs sets the right AttributeDefinition, the Window-class gets it and fills the attributes in to a form.
As I've understood the error, I have no permissions to access the Blocktable/Blocktablerecord/AttributeDefinitions/etc. in another class than myPlugin.cs.
Kind Regards
Klaus