Code Red > .NET

Calling a function from WPF form causes System.ArgumentException

(1/2) > >>

Jeff_M:
I've come across an issue that has me quite perplexed. I have a function to create a profile in Civil 3D which has a number of arguments expected to be passed to it. For testing purposes, in that function is also code to create new variables with the same objects as those arguments and a call to the C3D function to create the profile. I also have 2 commands, one that calls the function directly with null objects (as I only want it to use those for testing in the function) and the other that opens a WPF form filled with objects to select which are then passed to the function.

When I use the testing command, the profile is created as expected. When I use the command with the form, it errors out with the System.ArgumentException even when I am having it only use the testing portion of the function which uses none of the passed arguments.

So, what could be causing the WPF form to wreak havoc with this function? Here's a snip of the code:


--- Code - C#: ---                PromptEntityOptions opt = new PromptEntityOptions("\nSelect an Alignment");                opt.SetRejectMessage("\nObject must be an alignment.\n");                opt.AddAllowedClass(typeof(Alignment), true);                ObjectId testAlignID = ed.GetEntity(opt).ObjectId;                Alignment oAlignment = trans.GetObject(testAlignID, OpenMode.ForRead) as Alignment;                ObjectId testLayerID = oAlignment.LayerId;                ObjectId testSurfaceId = doc.GetSurfaceIds()[0];                ObjectId testStyleId = doc.Styles.ProfileStyles[0];                ObjectId testLabelSetId = doc.Styles.LabelSetStyles.ProfileLabelSetStyles[0];                //--------------------------------------------------------------------------------------------------                try                {                    //The following line works when function is called directly from a command, fails when called from the WPF window.                    ObjectId otherprofileId = Profile.CreateFromSurface("Other Profile", testAlignID, testSurfaceId, testLayerID, testStyleId, testLabelSetId); 

Jeff_M:
Of course I discover the solution almost as soon as I post this. Once I added the following it works as it should.


--- Code - C#: ---            using (DocumentLock dl = doc.LockDocument())            {                 ...the code to create the profile here             } 

MickD:
 :-)

Greg B:
I was going to suggest that solution.

MexicanCustard:
BTW,  it's not a WPF form.  It's a WPF window.  Semantics I know but using the word form with WPF makes my skin crawl. : :-)

Navigation

[0] Message Index

[#] Next page

Go to full version