Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jan 25, 2011 10:46 pm Post subject: Using RichText with .NET 4 |
|
|
This FAQ applies to Virtual Tree versions prior to 4.2. If you compile an application against the .NET 4 Framework and are using RichText with Virtual Tree versions prior to 4.2 then you may encounter a FileLoadException when the application is run with the following message:
Quote: | 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 |
The problem is that in .NET 4 Microsoft decided (by default) to not keep backward compatibility for loading mixed mode assemblies compiled using C++ against .NET 2. The Infralution.RichText assembly is compiled against .NET 2 to allow for backward compatibility and so cannot by default be used in a .NET 4 application.
In Version 4.2 (and later) of Virtual Tree Rich Text rendering is implemented entirely in managed code eliminating the need for the Infralution.RichText assembly and avoiding this problem.
If you need to use RichText in a .NET 4 application you can fix this issue by adding a configuration file for your application with the following Startup attribute:
Code: | <configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
</startup>
</configuration>
|
This enables backward compatible loading of mixed mode assemblies. Mixed mode assemblies compiled against .NET 4 will still load OK as well.
It is also possible to set this configuration programmatically by adding the following method (EnableCLR2Binding) to your application and calling it before your application loads any assemblies:
Code: | [ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
interface ICLRRuntimeInfo
{
void xGetVersionString();
void xGetRuntimeDirectory();
void xIsLoaded();
void xIsLoadable();
void xLoadErrorString();
void xLoadLibrary();
void xGetProcAddress();
void xGetInterface();
void xSetDefaultStartupFlags();
void xGetDefaultStartupFlags();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void BindAsLegacyV2Runtime();
}
private static void EnableCLR2Binding()
{
ICLRRuntimeInfo rtInfo = (ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(Guid.Empty, typeof(ICLRRuntimeInfo).GUID);
rtInfo.BindAsLegacyV2Runtime();
} |
_________________ Infralution Support |
|