 |
|
|
 |
|
 |
I was trying to bottom out why Static members are thread safe and I got some interesting info about why and something call ThreadStatic attribute.
http://blog.binaryjam.com/simon/archive/2004/03/18/146.aspx
|
|
|
|
 |
|
 |
Hi Guys, I have just recently started to work in the dot net arena. So as I was trying different examples I installed an assembly in the GAC by a simple drag and drop approach to the winnt\assembly directory. I kind of forgot about this assembly for a while as I went on trying some other things, I later fixed the version of my assembly to 1.0.0.0. and recompiled it many times over as I continued with my experiments. The main problem I am facing now is that I am unable to delete this assembly from the gac. Here are the outputs I am getting C:\>gacutil /lr ExampleDll Microsoft (R) .NET Global Assembly Cache Utility. Version 1.0.3705.0 Copyright (C) Microsoft Corporation 1998-2001. All rights reserved. The Global Assembly Cache contains the following assemblies: ExampleDll, Version=1.0.1188.31895, Culture=neutral, PublicKeyToken=c73a3aadb8 8be979, Custom=null SCHEME: <WINDOWS_INSTALLER> ID: <MSI> DESCRIPTION : <Windows Installer> The cache of ngen files contains the following entries: Number of items = 1 C:\>gacutil /uf ExampleDll Microsoft (R) .NET Global Assembly Cache Utility. Version 1.0.3705.0 Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.
Assembly: ExampleDll, Version=1.0.1188.31895, Culture=neutral, PublicKeyToken=c73a3aad b88be979, Custom=null Assembly could not be uninstalled because it is required by Windows Installer Unable to uninstall: assembly is required by one or more applications Pending references: SCHEME: <WINDOWS_INSTALLER> ID: <MSI> DESCRIPTION : <Windows Installer> Number of items uninstalled = 0 Number of failures = 0
I don’t how windows installer added a reference to this assembly. Any idea how I could delete this assembly from gac. I found this link http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/removal_of_assemblies_from_the_global_assembly_cache.asp but still have not been able to figure out how to delete/uninstall the dll
thanks in advance
|
|
|
|
 |
|
 |
This does seem an overly complex way of solving the problem. Surely you could have a class (called Foo, say) which has a static method (e.g. GetString). Then all you need to do in your code is call "Foo.GetString()".
|
|
|
|
 |
|
 |
Yes. This was discussed in other messages that were here. They seem to have been removed, however.
|
|
|
|
 |
|
 |
I agree with Nick. Although you've shown us some pretty nifty code, static methods make it unnecessary. Putting such methods as static members of a class is a good way to keep them grouped and organized.
Regards,
Alvaro
|
|
|
|
 |
|
 |
The major difference between a global function and a static method of a class is a stylistic one. To access a method I need to create an object: it's the point of confusion and, sometimes, minor inconveniences. Try to write with default constructors only - you will be unhappy pretty soon not because it is working or does not work but because it's just cumbersome!
BTW, can anybody "explain" me why do I need to use the "new" operator all the time? If every object is created in the heap anyway then why to type "new"? Am I missing something?
|
|
|
|
 |
|
 |
>Try to write with default constructors only -
>you will be unhappy pretty soon not because
>it is working or does not work
>but because it's just cumbersome!
By default constructor you mean no arguments, right? I would assume you would want to pass in as few arguments as possible, zero being optimal, but not always possible.
I would guess the "new" is mainly for clarity - shouting "Here is a new object!" kind of thing.
Craig Dodge
A catchy signature should appear here.
|
|
|
|
 |
|
 |
Right, I meant "no arguments" constructor. What I was trying to say is that almost all the code I've written over years uses some initialization via parameters and some cleanup. If you do not have parameterized constructors you are forced to write is something like the following:
Type obj;
o.Init( param1, param2);
...
o.Cleanup();
With Java/C# syntax you'll write (because you have parameterized constructors):
Type obj = new Type( param1, param2 );
// why duplicate Type? There are cases for that but majority of
// declarations are looking exactly like this one.
...
obj.Cleanup(); // you need cleanup anyway
With VB you'll write:
Dim obj As Type
' or 'As New Type' then you'll save on "Set Nothing" but loose on every call
Set obj = New Type
obj.Init( param1, param2 )
...
obj.Cleanup();
Set obj = Nothing
The "problem", from my point of view, is that the only thing I really wanted to write can be expressed in C++ as the following:
{
Type obj( param1, param2 );
...
}
Less typing and much more readable IMHO.
Self-Correction: 'Java-people' in CLR team made a concession and now you can use 'using' keyword in C# starting from Beta 2. Technically, it's the same thing as the constructor/destructor pair but it looks just horrible in a code flow.
|
|
|
|
 |
|
 |
To access a method I need to create an object
Wrong! If it's a static method you don't need an object at all. That's what differenciates a static method from an instance method (in C# or Java).
So if you have a class like this:
public class C
{
public static void sm() { };
public void im() { };
}
Then I can call the sm method without creating an instance of C, like this:
C.sm();
To call the im method, then I would need an instance of C, which must be created with new, like this:
C c = new C();
c.im();
why do I need to use the "new" operator all the time?
Using new makes it obvious that you're creating an instance of a class, as opposed to creating an instance of a value type such as a struct.
|
|
|
|
 |
|
 |
I admit I missed this part of the syntax and the remark from Mike Burston in the parallel thread gives an excellent example of this syntax.
But, sorry, I'm still not convinced that the variable declaration syntax in C# is not just an annoyance. You have pointed correctly that there is a difference between instantiation of value type and class type dictated by the implementation of CLR. But the difference itself is a very artificial one. Definition of complex value types looks as after-thought in attempt to improve performance of GC-based memory manager. It's not logically following the language structure. Boxing/un-boxing rule confuses issue even more and will lead to a lot of trouble in a mixed environment.
The whole beauty of C++ approach is that I treat and think about entities the same way - either primitive types or derived types. The reasonably fresh example of the strength of this approach was from one of my friends: they have had a "status code" type defined in the system and the original type was "DWORD". Recently they extended it to a class but with C++ they were able to implement the class in a way that most of the system didn't notice the difference. Is it possible with CLR's distinction between a value type and a class? May be "yes", but it will be tricky to implement, I guess, just because of the difference in semantics.
Of cause, I may be wrong, but I'm not convinced yet.
|
|
|
|
 |
|
 |
You can still think about everything the same way. )
int i = new Int32();
Regards,
Jeff Varszegi
|
|
|
|
 |
|
 |
Using new makes it obvious that you're creating an instance of a class, as opposed to creating an instance of a value type such as a struct.
All UserDefinedTypes structs or classes need a new to create an instance
|
|
|
|
 |
|
 |
why do I need to use the "new" operator all the time?
Using new makes it obvious that you're creating an instance of a class, as opposed to creating an instance of a value type such as a struct.
It's actually necessary, and it's not included just for code readability. Without a new-object keyword, there'd be confusion every time you attempted to call a method named the same as a class, and vice versa.
Of course, if global functions were part of the language, you could always make a factory global method that would return an instance of a class.
Regards,
Jeff Varszegi
|
|
|
|
 |
|
 |
That's a nifty trick- but if I remember rightly, C# has static member functions... I think ...?
There would be much less overhead just to create a class with a static function to do this (no memory allocation)
am I missing the point?
cool code, anyway
|
|
|
|
 |
|
 |
If what you want to do is create a new variable, that would involve memory allocation anyway, right?
If you want to modify an existing variable, yes, you're right, it would be an unneed memory allocation.
Craig Dodge
A catchy signature should appear here.
|
|
|
|
 |
|
 |
The point being made is that 'static' functions given you an easy ability to group 'global' functions into a 'class' that is really just a namesspace for holding such functions. There is no need to use constructors, 'new', or the operator overload.
A (rough) example :
class AClass; // a class that holds some data we want to work on
public class GlobalFunctions // the 'class' that holds our global functions
{
public static void DoSomething(AClass a) {...}
public static AClass GetAClass() {...}
public static String Reverse(String s) { ... }
...
}
class Test
{
static void Main() {
AClass a = new AClass();
GlobalFunctions.DoSomething(a);
AClass b = GlobalFunctions.GetAClass();
String s = GlobalFunctions.Reverse("string");
}
}
Reg : "Well, what Jesus blatantly fails to appreciate is that it's the meek who are the problem."
|
|
|
|
 |
|
 |
Thanks for the example, that makes the point easier to understand.
Craig Dodge
A catchy signature should appear here.
|
|
|
|
 |
|
 |
Mike's code illustrates the best workaround methinks. But good article anyway. Cool code.
|
|
|
|
 |
|
 |
Excellent example! Thanks!
|
|
|
|
 |