|
Assemblies are loaded into an AppDomain when you Type they define is required. You cannot unload assemblies from an AppDomain without shutting down the AppDomain (closing/killing the process is one way of doing this).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Similar to what Heath said, but you can create your own AppDomain's and load the assemblies into there. Then, when you want to unload the assembly, destroy the AppDomain. I think there's some article on MSDN about doing that.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
Well I did try following that example and it worked up to a point. I get Serialization exceptions because .NET is trying to serialize System.Threading.Thread and other System classes. I can only modify my own classes to meed serialization requirements. What do I do about the System classes I need objects of sever System types in the assembly that I am trying to load into a separate AppDomain.
For more than 2 years I did not have any such issue because I was loading assemblies into the default AppDomain. But I now have a need to dynamically load and unload them. Do you know of a solutions that will not try to serialize System classes. I can only modify my classes with MarshalByRefObject or [Serializable].
Thanks
Robert
|
|
|
|
|
Why can't I have two functions with the same name and the same input paramters, but different return types. The two functions are obviously different. I did this in C++ with no problems. Is there any way to do it in c#?
Gary Kirkham
A working Program is one that has only unobserved bugs
He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot
Who you are in Christ
|
|
|
|
|
It's not allowed by the CLI. See ECMA 335, section 10.2 (Overloading), with one exception: overloaded operator methods can differ only by return type.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks...I wonder why the C# development team thought that capability wasn't useful? O' Well, maybe I am the only one who used it in C++.
Gary Kirkham
A working Program is one that has only unobserved bugs
He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot
Who you are in Christ
|
|
|
|
|
It's not C#: it's the CLI - the Common Language Infrastructure (sometimes Interface), which describes assembly and type metadata (Common Type System, or CTS), as well as the Common Intermediate Language (CIL) and a few other things. It's what makes the language independence possible.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You can't because C# doesn't support it. Overloading selections are done only on functions names and argument lists only. Return types are not considered by the compiler.
7.4.2 Overload Resolution[^]
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Since no one else said it, I guess I will:
You did NOT do this in C++.
class A
{
int doSomething() {}
void doSomething() {} // causes an error
};
Here's the first error it will cause:
error C2556: 'void A::doSomething(void)' : overloaded function differs only by return type from 'int A::doSomething(void)'
It will also cause other errors indirectly, when/if the compiler fails to recover from the error and continue analysis.
The C++ standards forbid this, just as C# does.
|
|
|
|
|
I stand corrected, I must be getting senile in my old age.
Gary Kirkham
A working Program is one that has only unobserved bugs
He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot
Who you are in Christ
|
|
|
|
|
Not a big deal. I just couldn't have you bad-mouthing C#'s overloading.
|
|
|
|
|
Hello world!
I have a class and I wish to get a reference to one of its member variables at runtime.
class foo
{
public string bar1;
public string bar2;
..
}
I have called foo.GetFields() and I am the proud owner of an array of FieldInfo structures giving me information about all of the type's member variables. I can see my strings (checkboxes/bears) in the list.
My question is: How can I take this FieldInfo data, and get a reference to the desired variable and hence manipulate it??
Many thanks in advance,
Charlie (C:=
|
|
|
|
|
You've already got it: the FieldInfo . If you want to get or set a field's value, use FieldInfo.GetValue and FieldInfo.SetValue . If the fields are instance fields, you must pass the object whos fields you want to retreive.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Where does foo and bar come from, as it seems to be standard in using in examples?
Does it come from FUBAR?
Thanks
|
|
|
|
|
yes... now, what's a fubar?
|
|
|
|
|
Ok, here's the senario:
I have two projects in my solution, one of which (project A) has a custom control, and the second (Project B) has a form that uses the custom control. Frequently, if I have opened the project B form in the designer and then re-compile, Project A's dll cannot be written to the output directory because the designer is using it (at least that's what I presume is the reason it can't be written). Closing the designer window in Visual Studio doesn't help. Even closing the *solution* and re-opening doesn't help!! I have to close Visual Studio completely and re-launch to be able to compile my solution again.
How can I avoid this problem, outside of not having these two projects in the same solution (I'm working in both at the same time).
Thanks!
~Steve
|
|
|
|
|
Steve Schaneville wrote:
How can I avoid this problem, outside of not having these two projects in the same solution (I'm working in both at the same time).
You can't. It's a bug in VS.NET 2002 and 2003. Here's to hoping it's been fixed in VS.NET 2005
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
oh. good news.
Thanks!!
~Steve
|
|
|
|
|
I have an instance of class A that publishes an event and several instances of class B that subscribe to it. How can I get a B instance to UNsubscribe from the event?
|
|
|
|
|
It's just like subscribing to the event, except that you use -= instead of +=
intanceOfA.FireTorpedoes -= new EventHandler(intanceOfA_FireTorpedoes);
Charlie
if(!curlies){ return; }
|
|
|
|
|
I have a datatable and performaing select method on that.
I have to pass array of values to the select method,
is there any way how i can do that?
Here goes the code
string[] emp;
dtemp.select()- How should i pass array of strings inside the function.
|
|
|
|
|
You can't. Instead, split your array and pass each value as part of the WHERE clause:
private DataRow[] SelectRows(string field, string[] values)
{
if (field == null || values == null)
throw new ArgumentNullException(field == null ? "field" : "values");
if (values.Length < 1) throw new ArgumentException();
StringBuilder sb = new StringBuilder();
for (int i=0; i<values.Length; i++)
{
sb.AppendFormat("{0} = {1}", field, value);
if (i < (values.Length - 1))
sb.Append(" AND ");
return dataTable1.Select(sb.ToString());
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am creating a windows app in C# with a ListView control. It has three columns which are being filled with a ListViewItem (One .Text and two .SubItems being added to generate)
My problem is I can not figure out how to grab the text entered in one of the columns when someone clicks on one of the items. FullRowSelect is set to True and I'd like to keep it that way if possible. The first row is a list of FileNames, second the size and the third a mod date. On click, I want to simply open the file that was selected.
I've also noticed, while trying the SelectedItems/SelectedIndices options that they tend to be called twice on change. The first is a null value (for an Int??) and the second is the correct option.
Any help would be appreciated, I'm still going through articles on the Web regarding this control, but everything is oriented on sorting - not how to execute some code based on the selection. Thanks!
|
|
|
|
|
Get the index of the ListViewItem and get the sub item:
private void listView1_SelectedIndexChanged(object sender,
EventArgs e)
{
int index = listView1.SelectedIndex;
if (index >= 0)
{
ListViewItem item = listView1.Items[index];
string value = item.SubItems[1];
MessageBox.Show(value);
}
} If you actually want the column that the user clicked on, you need to perform a hit text:
private int GetColumnIndex()
{
Point p = listView1.PointToClient(
new Point(MousePosition.X, MousePosition.Y));
int width = 0;
foreach (ColumnHeader header in listView1.Columns)
{
width += header.Width;
if (p.X < width) return header.Index;
}
return -1;
} You could call this method to get the column index (be mindful that it could be -1) and use that as the index into ListViewItem.SubItems .
Microsoft MVP, Visual C#
My Articles
|
|
|
|