.NET

Reply
Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 1 of 7 (312 Views)

Unable to find assembly

312 Views, 6 Replies
02-17-2012 02:00 AM

Hello,

I have a dll which shows simple dialog, which in its constructor reads from a file located in the same folder as the dll, to populate some of the controls in the form, like combo boxes. The assembly works perfectly at local pc, but when I take release copy of the dll and the file at work, I cannot read from the file.

I am able to load the dll with the Netload, but when i start the command it shows - "Unable to find assembly 'Pressurized Pipes, Version=1.0.0.0, Culture=neutral, PublicKey Token=null'. And when I click OK button shows second dialog saying "Unhandled exception has occurred in a component in your application. If you continue, the application will ignore this error and attempt to continue. Invalid Argument=Value of '0' is not  valid for 'SelectedIndex'. Parameter name: SelectedIndex.

Details:

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text ************** System.ArgumentOutOfRangeException: InvalidArgument=Value of '0' is not valid for 'SelectedIndex'. Parameter name: SelectedIndex at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value) at Plumbing_Pipes.Pressurized_Pipes_Form.populatePipeTypeComboBox() at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

It seems to me that I am not able to Deserialize the file and read from the list in the file, which list I use to populate the combobox.

I am using just the name of the file to deserialize it, assuming that the dll will look in the folder where the dll is located. Is that what I am doing wrong.

Thank you in advance.

 

 

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 2 of 7 (293 Views)

Re: Unable to find assembly

02-17-2012 05:06 AM in reply to: DLyaskov

i guess you fill a combobox with some data from the file, but the file was not found, so the combobox has no items and you try to select the first item of the combobox

 

don't select the item if the combobox is empty - that should solve the error

 

but what you really need is find the file you want to read

 

how do you specify the path for that file? check if the path is not different on the other computer

Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 3 of 7 (277 Views)

Re: Unable to find assembly

02-17-2012 01:38 PM in reply to: DLyaskov

Hello,

 

and thank you for you quick responce. 

 

The file which holds some data for initializing the controls is located in the same folder as dll. This is the constructor for the form.

 

        public Pressurized_Pipes_Form()

        {

            InitializeComponent();

 

            FileStream fs = new FileStream("Pressurized Pipe Settings.bin", FileMode.Open, FileAccess.Read);

            BinaryFormatter bf = new BinaryFormatter();

            try

            {

                listPipeTypes = bf.Deserialize(fs) as List<PipeType>;

            }

            catch (Exception e)

            {

                MessageBox.Show(e.Message);

            }

            finally

            {

                fs.Close();

            };

 

        }

 

and later I try to populate the combobox like that: 

 

        private void populatePipeTypeComboBox()

        {

            this.cbPipeType.Items.Clear();

 

            foreach (PipeType pt in listPipeTypes)

            {

                this.cbPipeType.Items.Add(pt.PipeTypeName);

            }

 

            this.cbPipeType.SelectedIndex = iPipeType;

        }

 

I would like to be able to have dll and the file in same folder.  It still puzzels me why the code works in one case and not in others. 

Is there a bullet proof way to tell my consturctor: Take the folder of where the dll is run from and look for the file in it. 

I dont like to have absolute paths since they will change from pc to pc.

 

Thank you for you help.

 

Valued Mentor
fieldguy
Posts: 371
Registered: ‎03-31-2005
Message 4 of 7 (265 Views)

Re: Unable to find assembly

02-17-2012 03:28 PM in reply to: DLyaskov

Just guessing here.

 

Perhaps you can use getexecutingassembly path or location to add to the file you are trying to open?

*Expert Elite*
dgorsman
Posts: 5,367
Registered: ‎10-12-2006
Message 5 of 7 (263 Views)

Re: Unable to find assembly

02-17-2012 03:59 PM in reply to: DLyaskov

System.Reflection namespace may offer some tools of use.  Or, if you are demand loading you could check the registry to check the demand load path.

 

Myself, I'm not too keen on forcing a datafile to exist in one location unknown until runtime; if it were up to me I'd follow other applications and create a registry key to point to the install folder and a use a hard-coded relative path in the code, or a full path in the registry and a hard-coded file name, or a configuration file in the active drawings folder, or some similar means of explicitly locating the file.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 6 of 7 (234 Views)

Re: Unable to find assembly

02-19-2012 11:15 PM in reply to: DLyaskov

If you have the file in some of AutoCAD search paths, then you can use this:

 

Dim myPath As String = HostApplicationServices.Current.FindFile("myFile.ext", HostApplicationServices.WorkingDatabase, FindFileHint.Default)

Contributor
DLyaskov
Posts: 14
Registered: ‎06-24-2010
Message 7 of 7 (208 Views)

Re: Unable to find assembly

02-24-2012 11:54 PM in reply to: DLyaskov

Thanks guys for all of your suggestions.

 

Last couple of days I was experimenting with all of them and none of them helped.  I really liked and implemented the idea of using reflection to find the path to the dll and thus location of my file.  I am really scared to work with registry, and going in that direction for a simple dll like mine, was no for me.  

 

Just for fun, I tried to test my dll on third pc at work and for my surprise it worked perfectly.   Both pcs, where I was able to run the dll, have AutoCAD 2012, while the one where I cannot, have AutoCAD MEP 2011 and Revit 2012 installed. 

 

It seems to me now, that may be not finding the file, but deserialization of my list is the culprit.  The list is not deserialize, combobox is empty and exception is thrown when I try to set the selected item to the first one.

 

Any ideas if having AutoCAD MEP 2011 and Revit 2012 can mess up the serialization / deserialize process?

 

Thanks.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.