07 February 2013 CLR Robert Muehsig

Seit .NET 4.0 gibt es einen neuen Global Assembly Cache (GAC) welcher unter diesem Pfad zu finden ist:

C:\Windows\Microsoft.NET\assembly

Alle .NET 4.0 bzw. CLR 4.0 Applikationen nutzen diesen GAC.

Was ist mit dem "alten” GAC?

Den alten GAC gibt es nach wie vor unter diesem Pfad:

C:\Windows\assembly

Dieser ist nach wie vor für .NET 2.0 - .NET 3.5 bzw. CLR 2.0 Applikationen zuständig.

CLR? .NET Framework Version? Ist das nicht dasselbe?

Das Thema ist etwas komplexer, aber als Kurzfassung finde ich das ganz gut:

CLR + Libraries = .NET Framework

Wobei die CLR die Basis für die Ausführung ist. Mit diversen .NET Framework Versionen kamen mehr Libraries hinzu, jedoch gab es nur 2 große CLR Versionen bis heute – die Version 2.0 und 4.0.

Quelle

Warum gab es diese Änderung?

An dieser Stelle möchte ich direkt meine Quelle benennen: Stackoverflow

“In .NET Framework 4.0, the GAC went through a few changes. The GAC was split into two, one for each CLR.

The CLR version used for both .NET Framework 2.0 and .NET Framework 3.5 is CLR 2.0. There was no need in the previous two framework releases to split GAC. The problem of breaking older applications in Net Framework 4.0.

To avoid issues between CLR 2.0 and CLR 4.0 , the GAC is now split into private GAC’s for each runtime.The main change is that CLR v2.0 applications now cannot see CLR v4.0 assemblies in the GAC.”

Grund für die Änderung:

For example, if both .NET 1.1 and .NET 2.0 shared the same GAC, then a .NET 1.1 application, loading an assembly from this shared GAC, could get .NET 2.0 assemblies, thereby breaking the .NET 1.1 application

“The CLR version used for both .NET Framework 2.0 and .NET Framework 3.5 is CLR 2.0. As a result of this, there was no need in the previous two framework releases to split the GAC. The problem of breaking older (in this case, .NET 2.0) applications resurfaces in Net Framework 4.0 at which point CLR 4.0 released. Hence, to avoid interference issues between CLR 2.0 and CLR 4.0, the GAC is now split into private GACs for each runtime.”

Ein weiterer Punkt:

“Mark Miller said... June 28, 2010 12:13 PM

Thanks for the post. "Interference issues" was intentionally vague. At the time of writing, the issues were still being investigated, but it was clear there were several broken scenarios.

For instance, some applications use Assemby.LoadWithPartialName to load the highest version of an assembly. If the highest version was compiled with v4, then a v2 (3.0 or 3.5) app could not load it, and the app would crash, even if there were a version that would have worked. Originally, we partitioned the GAC under it's original location, but that caused some problems with windows upgrade scenarios. Both of these involved code that had already shipped, so we moved our (version-partitioned GAC to another place.

This shouldn't have any impact to most applications, and doesn't add any maintenance burden. Both locations should only be accessed or modified using the native GAC APIs, which deal with the partitioning as expected. The places where this does surface are through APIs that expose the paths of the GAC such as GetCachePath, or examining the path of mscorlib loaded into managed code.

It's worth noting that we modified GAC locations when we released v2 as well when we introduced architecture as part of the assembly identity. Those added GAC_MSIL, GAC_32, and GAC_64, although all still under %windir%\assembly. Unfortunately, that wasn't an option for this release.”

Für mich war die Nachricht ein kleiner “Aha”-Moment. Zudem wusste ich auch nicht, dass der seltsame “Assembly-Viewer” aus Windows 8 wieder entfernt wurde:

image

Fazit:

Gut zu wissen.

Dr. McCoy and Captain Kirk approve


Written by Robert Muehsig

Software Developer - from Saxony, Germany - working on primedocs.io. Microsoft MVP & Web Geek.
Other Projects: KnowYourStack.com | ExpensiveMeeting | EinKofferVollerReisen.de