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=126.96.36.199, 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.
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(In
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.
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
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.
FileStream fs = new FileStream("Pressurized Pipe Settings.bin", FileMode.Open, FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter();
listPipeTypes = bf.Deserialize(fs) as List<PipeType>;
catch (Exception e)
and later I try to populate the combobox like that:
private void populatePipeTypeComboBox()
foreach (PipeType pt in listPipeTypes)
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.
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 have the file in some of AutoCAD search paths, then you can use this:
Dim myPath As String = HostApplicationServices.Current.FindFile("myFile.e
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?
Access a broad range of knowledge to help get the most out of your products and services.