Only .NET 1.0 assemblies in the GAC


J

Jo Vermeulen

Hello,

I'm experiencing some trouble with the Global Assembly Cache (GAC). It
contains only assemblies of the .NET 1.0 framework (version 1.0.5000.0)
although I installed the .NET framework 1.1. I used gacutil.exe /i to
manually load the 1.1 assemblies in the GAC, but that does not seem to
work. The assemblies are not loaded into the GAC, although the output of
gacutil.exe /i tells me so. When I view all assemblies using gacutil.exe
/l, I only see the 1.0 ones. Same thing if I look into "C:\WINNT\assembly\".

I want to load the 1.1 assemblies in the GAC because I am experiencing
trouble with dynamic loading of assemblies. For instance, I load the
System.Windows.Forms.dll using information from the System.Environment
class. Apparantly this says I am using the .NET framework 1.1, so I
dynamically load version 1.1.4322. I also had to add references to
System.Windows.Forms, System.Drawing etc. to get the code to compile.
When I run it, Visual Studio starts loading the 1.0.5000.0 versions out
of the GAC.

This gives me extremely weird behaviour such as receiving an
InvalidCastException on this code (it's in C#):

Button swfObject = (Button)(Activator.CreateInstance(classType));

Where "classType" is a System.Windows.Forms.Button Type instance!

Any help would be greatly appreciated.

Kind regards,
 
Ad

Advertisements

M

Mattias Sjögren

Jo,
It contains only assemblies of the .NET 1.0 framework (version 1.0.5000.0)

The 1.0.5000 assemblies are from v1.1 of the framework. Most
assemblies in the v1.0 framework had assembly version 1.0.3300.

Button swfObject = (Button)(Activator.CreateInstance(classType));

Why do you use Activator.CreateInstance instead of new when you
apparently have a reference to the assembly containting the type?



Mattias
 
J

Jo Vermeulen

Mattias said:
Jo,




The 1.0.5000 assemblies are from v1.1 of the framework. Most
assemblies in the v1.0 framework had assembly version 1.0.3300.

Oh... :-s

Seems to me that's confusing versioning :p So you are saying the .NET
1.1 framework's version is 1.1.4322 but the DLL's version number is
1.0.5000?

This is what I see in the VS.NET output window:

________
'DefaultDomain': Loaded
'c:\winnt\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols
loaded.

This was my dynamic load of mscorlib, but it seems to be version 1.1.4322?

<snip desc="load program" />
: Loaded
'c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll',
No symbols loaded.

This was VS.NET which loaded system.dll.

: Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll',
No symbols loaded.

This was VS.NET which loaded system.xml.dll.

: Loaded
'c:\winnt\microsoft.net\framework\v1.1.4322\system.windows.forms.dll',
No symbols loaded.

This was my dynamic load of system.windows.forms.dll, but it also seems
to be version 1.1.4322?

: Loaded
'c:\winnt\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll',
No symbols loaded.

This was VS.NET which loaded system.windows.forms.dll.

: Loaded
'c:\winnt\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll',
No symbols loaded.

This was VS.NET which loaded system.drawing.dll.
________

Maybe I should dynamically load the appropriate System.Windows.Forms dll
from the GAC instead of specifying it's absolute location.

This is the code I currently use to load it:

________
string sysRoot = Environment.GetEnvironmentVariable("systemroot");
string version = System.Environment.Version.ToString();
version = version.Substring(0, version.LastIndexOf("."));
string assemblyName = sysRoot + @"\Microsoft.NET\Framework\v" +
version + @"\" + "System.Windows.Forms.dll";
GuiAssembly = Assembly.LoadFrom(assemblyName);
________

I tried using Assembly.LoadFrom("System.Windows.Forms") but that didn't
work (FileNotFoundException if I'm not mistaken). Is there any way to
fetch the DLL from the GAC? LoadWithPartialName could be an option,
although MSDN does not recommend to use it.
Why do you use Activator.CreateInstance instead of new when you
apparently have a reference to the assembly containting the type?

This is a fictional example used for testing since I had lots of
problems when casting between System.Windows.Forms objects. Therefore I
tried to cast from a Button to a Button, and even that gives me an
InvalidCastException!

Kind regards,
 
M

Mattias Sjögren

Seems to me that's confusing versioning :p So you are saying the .NET
1.1 framework's version is 1.1.4322 but the DLL's version number is
1.0.5000?
Exactly.


'DefaultDomain': Loaded
'c:\winnt\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols
loaded.

This was my dynamic load of mscorlib, but it seems to be version 1.1.4322?

No the mscorlib assembly version is still 1.0.5000. The version you
see in the file path is the framework version.

Maybe I should dynamically load the appropriate System.Windows.Forms dll
from the GAC instead of specifying it's absolute location.

I still don't understand why you want to load it dynamically.

string sysRoot = Environment.GetEnvironmentVariable("systemroot");
string version = System.Environment.Version.ToString();
version = version.Substring(0, version.LastIndexOf("."));
string assemblyName = sysRoot + @"\Microsoft.NET\Framework\v" +
version + @"\" + "System.Windows.Forms.dll";

You can replace most of that with
RuntimeEnvironment.GetRuntimeDirectory().

I tried using Assembly.LoadFrom("System.Windows.Forms") but that didn't
work (FileNotFoundException if I'm not mistaken). Is there any way to
fetch the DLL from the GAC?

Personally I'd just use

Assembly winforms = typeof(System.Windows.Forms.Control).Assembly;

if I had a compile time reference to it.



Mattias
 
Ad

Advertisements

K

Kris Luyten

On Thu, 08 Jul 2004 14:59:41 +0200, Mattias Sjögren wrote:
I still don't understand why you want to load it dynamically.

The reason we do this is the following: we are building a dynamic user
interface renderer on .Net. This renderer takes an XML-document containing
a user interface description as input, reads a vocabulary for a specific
widget set, and tries to render the user interface according to this
vocabulary. We use the UIML (http://www.uiml.org) specification to
describe the user interfaces in XML. We have support for part of the Gtk#
widget set, and we are adding support for SWF now.

Our renderer, uiml.net (https://sourceforge.net/projects/uimldotnet/), has only minimal
knowledge about a widget set. It loads the widgets dynamically according
to the vocabulary that is used. To enable the renderer to make use of
other widget sets easily, and to support evolution in widget set libraries
everything is loaded dynamically instead of statically. The widget
specific code (like references to widget set specific class names) in the
rendering engine is limited to the absolute minimum. This way we try
to make use of the possibility to use different kinds of widget sets that
are available for the .Net platform without writing any widget set
specific code.


Thanks for your useful replies,
Kris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top