Posts

Showing posts with the label ASSEMBLY

Like a little Assembly with your GAC?

Q: Is it posssible to get an assembly out of the GAC to another folder? Let's say you GAC-ed an assembly but you deleted the source by accident? A: The assembly would be stored in this folder <windowsdir>\assembly\GAC\<Assembly Name>\Version_PublicKeyToken. You can get that using the copy command from the command prompt and using "CD dirname". From Windows Explorer, you cannot do it as Explorer has a custom view of the windows\assembly folder that hides the actual files and subfolders. That's for 1.1 Assemblies. 2.0 Assemblies would be in <windowsdir>\assembly\GAC_MSIL\<Assembly Name>\Version_PublicKeyToken. Q: GAC_32, GAC_MSIL, GAC_64 - What gives? Specifically why is there is a GAC_32 and a GAC_MSIL folder? Is it because some assemblies are compiled to x86 machine code (GAC_32) and some assemblies are compiled to MSIL? What dictates where your assembly ends up? A: The GAC_MSIL cache contains assemblies that can be run in either 32-bit or ...

Dynamically Loading an Image from an External Assembly

This one came up recently in the C# newsgroup, so I thought I'd take a quick crack at it: private void button1_Click(object sender, EventArgs e) { Assembly asm = Assembly.LoadFrom(System.Environment.CurrentDirectory + @"\AssemblyResources.dll"); Stream strm = asm.GetManifestResourceStream((string)asm.GetManifestResourceNames()[0]); Bitmap b = (Bitmap)Image.FromStream(strm); pictureBox1.Image = b; } What you are doing is: 1) Assuming the "external" assembly is a managed assembly, and it's name is "AssemblyResources.dll", and it resides next to the executable (for ASP.NET you would have to use Server.MapPath or some combination of Request.PhysicalApplicationPath, or the like). We load the assembly into the AppDomain using the LoadFrom method. 2)We extract the resource into a stream using the GetManifestResourceStream method. 3) To make it easier to know the exact names of resources (which can be tricky) I use the GetManifestResourceNames method, whic...