2009-10-22 7 views
198

Während ein Projekt umgewandelt werden, die SlimDX verwendet, und hat daher nicht verwalteten Code, zu .NET 4.0 ich in den folgenden Fehler lautete:Was macht 'useLegacyV2RuntimeActivationPolicy' in der .NET 4-Konfiguration?

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

um gab mir die Lösung googeln, die dies auf die Anwendungen Config hinzuzufügen ist :

<configuration> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0"/> 
    </startup> 
</configuration> 

Meine Frage ist, was ist die tun? Ich kann keine Dokumentation darüber finden.

Antwort

155

Nach ein wenig Zeit (und mehr Suche), fand ich this blog entry von Jomo Fisher.

One of the recent problems we’ve seen is that, because of the support for side-by-side runtimes, .NET 4.0 has changed the way that it binds to older mixed-mode assemblies. These assemblies are, for example, those that are compiled from C++\CLI. Currently available DirectX assemblies are mixed mode. If you see a message like this then you know you have run into the issue:

Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

[Snip]

The good news for applications is that you have the option of falling back to .NET 2.0 era binding for these assemblies by setting an app.config flag like so:

<startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0"/> 
</startup> 

Es sieht also so aus, als ob sich die Laufzeit von Baugruppen im gemischten Modus geändert hat. Ich kann keine Details über diese Änderung finden oder warum es gemacht wurde. Das Attribut wird jedoch wieder auf CLR 2.0 geladen.

+26

Es ist hier erwähnenswert, dass inzwischen marklios Antwort (http://stackoverflow.com/questions/1604663/what-does-uselegacyv2runtimeactivationpolicy-do-in-the-net-4-config/2467255#2467255) bietet einen Link zu seine gründliche Erklärung zu dieser Veränderung. –

+1

Eine gründliche Erklärung hierzu finden Sie auf MSDN (obwohl es die oben erwähnte Lösung nicht explizit erwähnt): http://msdn.microsoft.com/en-us/magazine/ee819091.aspx –

+0

Was ist, wenn ich ' Ich habe dies sowohl der Konfiguration für meine Anwendung als auch einer Konfiguration für mein UnitTest-Projekt hinzugefügt und erhalte immer noch einen Fehler beim Laden der Datei, wenn ich Tests durchführe. Soll ich eine neue Frage stellen? – CodenameCain

116

Hier ist eine Erklärung, die ich vor kurzem schrieb, um mit der Ungültigkeit von Informationen über dieses Attribut zu helfen. http://www.marklio.com/marklio/PermaLink,guid,ecc34c3c-be44-4422-86b7-900900e451f9.aspx (Internet Archive Wayback Machine Link)

die relevantesten Bits zu zitieren:

[Installing .NET] v4 is “non-impactful”. It should not change the behavior of existing components when installed.

The useLegacyV2RuntimeActivationPolicy attribute basically lets you say, “I have some dependencies on the legacy shim APIs. Please make them work the way they used to with respect to the chosen runtime.”

Why don’t we make this the default behavior? You might argue that this behavior is more compatible, and makes porting code from previous versions much easier. If you’ll recall, this can’t be the default behavior because it would make installation of v4 impactful, which can break existing apps installed on your machine.

Der vollständige Beitrag erklärt dies im Detail. Bei RTM sollte die MSDN-Dokumentation besser sein.

+10

+1 für diese späte Follow-up, ist Ihre Erklärung sehr hilfreich! –

+0

Einverstanden. Sehr gute Erklärung in der Tat. – Roman

+0

@hvd: Während, wie ich verstehe, die Wayback Machine ziemlich zuverlässig ist, könnten Sie diese Antwort weiter verbessern, indem Sie relevante Abschnitte aus dem Link direkt in der Antwort zitieren? Danke für Ihre Hilfe! – BoltClock