SOFAgh / CADability

CADability is a pure .net class library for modeling and analyzing 3d data, both with your code and interactively. It comes with an optional Windows.Forms user interface, which can be adopted to other environments. It does not refer to other 3d modeling libraries. For data exchange you can use STEP, STL or DXF files.

Home Page:https://sofagh.github.io/CADability/CADabilityDoc/articles/general.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullReferenceException in ImportDxf.CreateHatch

dsn27 opened this issue · comments

commented

A NRE occures while importing the attached DXF file.

The reason is the casting of the list to an ICollection<IGeoObject>.
If there is no IGeoObject inside the list (like a Hatch) the cast will return null.

What was the intention of this cast? To get rid of all non IGeoObjects?

if (list.Count > 1)
{
GeoObject.Block block = GeoObject.Block.Construct();
block.Set(new GeoObjectList(list as ICollection<IGeoObject>));
return block;
}

128-210.01_neu.zip

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object
Source=CADability
StackTrace:
at CADability.GeoObject.GeoObjectList..ctor(ICollection`1 list) in C:\Development\Repos\SOFAgh\CADability\CADability\GeoObjectList.cs:line 50

CADability.dll!CADability.GeoObject.GeoObjectList.GeoObjectList(System.Collections.Generic.ICollection<CADability.GeoObject.IGeoObject> list) Line 50 C#
CADability.dll!CADability.DXF.Import.CreateHatch(netDxf.Entities.Hatch hatch) Line 737 C#
CADability.dll!CADability.DXF.Import.GeoObjectFromEntity(netDxf.Entities.EntityObject item) Line 136 C#
CADability.dll!CADability.DXF.Import.FindBlock(netDxf.Blocks.Block entity) Line 333 C#
CADability.dll!CADability.DXF.Import.CreateInsert(netDxf.Entities.Insert insert) Line 796 C#
CADability.dll!CADability.DXF.Import.GeoObjectFromEntity(netDxf.Entities.EntityObject item) Line 138 C#
CADability.dll!CADability.DXF.Import.FindBlock(netDxf.Blocks.Block entity) Line 333 C#
CADability.dll!CADability.DXF.Import.CreateInsert(netDxf.Entities.Insert insert) Line 796 C#
CADability.dll!CADability.DXF.Import.GeoObjectFromEntity(netDxf.Entities.EntityObject item) Line 138 C#
CADability.dll!CADability.DXF.Import.FindBlock(netDxf.Blocks.Block entity) Line 333 C#
CADability.dll!CADability.DXF.Import.CreateInsert(netDxf.Entities.Insert insert) Line 796 C#
CADability.dll!CADability.DXF.Import.GeoObjectFromEntity(netDxf.Entities.EntityObject item) Line 138 C#
CADability.dll!CADability.DXF.Import.FillModelSpace(CADability.Model model) Line 57 C#
CADability.dll!CADability.DXF.Import.CreateProject() Line 104 C#
CADability.dll!CADability.DXF.Import.Project.get() Line 75 C#
CADability.dll!CADability.Project.ImportDXF(string filename) Line 1778 C#
CADability.dll!CADability.Project.ReadFromFile(string FileName, string Format, bool useProgress, bool makeCompounds) Line 1807 C#
CADability.dll!CADability.Project.ReadFromFile(string FileName, string Format) Line 1838 C#
CADability.dll!CADability.FrameImpl.OnFileOpen(string fileName) Line 2335 C#
CADability.dll!CADability.FrameImpl.OnCommand(string MenuId) Line 997 C#
CADability.Forms.dll!CADability.Forms.CadFrame.OnCommand(string MenuId) Line 71 C#
CADability.Forms.dll!CADability.Forms.ToolBars.TagInfo.ButtonClicked(object sender, System.EventArgs e) Line 94 C#
System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.RaiseEvent(object key, System.EventArgs e) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ToolStripButton.OnClick(System.EventArgs e) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleClick(System.EventArgs e) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleMouseUp(System.Windows.Forms.MouseEventArgs e) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEventInteractive(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEvent(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) Unknown
CADability.App.exe!CADability.App.Program.Main(string[] args) Line 19 C#

list as ICollection<IGeoObject> was an invalid cast. Better define GeoObjectList list = new GeoObjectList();