This project has moved and is read-only. For the latest updates, please go here.

Saving a new Project

Nov 13, 2014 at 11:35 AM
Edited Nov 13, 2014 at 11:40 AM

I am very new to NShape.

Currently I load a project and display a diagram:
xmlStore1.DirectoryName = @"C:\Users\Public\Documents\NShape\Demo Projects";
xmlStore1.FileExtension = "nspj";
project1.AutoLoadLibraries = true;
display1.LoadDiagram("Diagram 1");
display1.ActiveTool = new SelectionTool();

Works fine.

after a while I want to create a new Project, and work (well O.K. currently i do nothing with the new project) with it:
project1.Name = "NewProject";
Diagram diagram = new Diagram("D1");
display1.ActiveTool = new SelectionTool();

Works fine. (Meaning I am shown an empty new diagram)

Then I want to save it:

I do not understand the following exception. Do I have ti intialice the Project in another way to be able to save it?

Dataweb.NShape.NShapeException wurde nicht behandelt.
Message=Entity type 'Core.Project' does not exist in the repository.
   bei Dataweb.NShape.Advanced.CachedRepository.FindEntityType(String entityTypeName, Boolean mustExist)
   bei Dataweb.NShape.Advanced.CachedRepository.Dataweb.NShape.Advanced.IStoreCache.FindEntityTypeByName(String name)
   bei Dataweb.NShape.XmlStore.WriteProjectSettings(IStoreCache cache)
   bei Dataweb.NShape.XmlStore.WriteProject(IStoreCache cache)
   bei Dataweb.NShape.XmlStore.DoSaveChanges(IStoreCache cache, String filePath)
   bei Dataweb.NShape.XmlStore.SaveChangesToFile(IStoreCache cache)
   bei Dataweb.NShape.XmlStore.SaveChanges(IStoreCache cache)
   bei Dataweb.NShape.Advanced.CachedRepository.SaveChanges()
   bei Dia_2.Form1.newToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\SeilerM\documents\visual studio 2010\Projects\Dia_2\Dia_2\Form1.cs:Zeile 47.
   bei System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   bei System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   bei System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   bei System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   bei System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   bei System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   bei System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   bei System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   bei System.Windows.Forms.ToolStrip.WndProc(Message& m)
   bei System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.Run(Form mainForm)
   bei Dia_2.Program.Main() in C:\Users\SeilerM\documents\visual studio 2010\Projects\Dia_2\Dia_2\Program.cs:Zeile 18.
   bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()

Thank you for any helpful answer or hint what I have missed in the documentation.

Nov 13, 2014 at 2:13 PM
After taking a quick look, I would say you have to add the shape libraries to the project (before creating it):
project1.AddLibrary(typeof(Ellipse).Assembly, false);
Please refer to the following chapters of the documentation for details on adding libraries:
  • "Basic Tutorial > Libraries"
  • "Class Reference > Namespace Dataweb.NShape > Project Class > AddLibrary Method"
Nov 13, 2014 at 5:09 PM
Edited Nov 13, 2014 at 5:11 PM
Hi KurtHolzinger,

Thank your for your quick response.
Either I did nor understand or it was not the solution:
I simplyfied the code to see what is wrong:

// Menue: New Project
private void newToolStripMenuItem_Click(object sender, EventArgs e)
        xmlStore1.DirectoryName = @"C:\Users\Public\Documents\NShape\Demo Projects";
        xmlStore1.FileExtension = "nspj";

        project1.Name = "NewProject";

        project1.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Ellipse).Assembly, false);

        Diagram diagram = new Diagram("D1");
// Menue: Save Changes
    private void saveToolStripMenuItem_Click(object sender, EventArgs e)
Still leaves me with the exception: "Entity type 'Core.Project' does not exist in the repository." if I try to save the project.

If I have a look at the "New Project" function I see, that I have created and assigned a diagram (which is shown), but no shapes on it.
Can I save an shape-empty Project?

Have a nice evening
Nov 14, 2014 at 8:21 AM
Yes, of course you can save an empty diagram.

After a closer look I finally spotted the problem:
instead of
because the latter only creates the repository (the XML file in this case) whereas the first one creates a new project.
Marked as answer by MatinSeiler on 11/14/2014 at 2:31 AM