.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to find assembly

6 REPLIES 6
Reply
Message 1 of 7
DLyaskov
750 Views, 6 Replies

Unable to find assembly

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.

 

 

6 REPLIES 6
Message 2 of 7
matus.brlit
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

Message 3 of 7
DLyaskov
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.

 

Message 4 of 7
fieldguy
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?

Message 5 of 7
dgorsman
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.
"I don't know" is the beginning of knowledge, not the end.


Message 6 of 7
matus.brlit
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)

Message 7 of 7
DLyaskov
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost