How to change .NET Framework Versions

  • 24 February 2022
  • 0 replies
  • 2329 views

Userlevel 5
Badge +20
 

How to change .NET Framework Versions

KB000686

PRODUCT
K2 blackpearl 0807 to 4.6.6
BASED ON
K2 blackpearl 0807
LEGACY/ARCHIVED CONTENT
This article has been archived, and/or refers to legacy products, components or features. The content in this article is offered "as is" and will no longer be updated. Archived content is provided for reference purposes only. This content does not infer that the product, component or feature is supported, or that the product, component or feature will continue to function as described herein.

 

This article describes how to change the .NET Framework version used by the K2 Server and Visual Studio 2010. A common error occurs if a newer version of a DLL is used than what K2 expects, with an error message of "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

 

 

There are three files that need to have the .NET Framework version updated:

  • K2HostServer.config (pre-4.6) or K2HostServer.exe.config (4.6 or later)
  • K2Server.config
  • K2Server.setup

The node that you need to update for the first file depends on which version of K2 you have installed. Refer to the correct version below.

The runtime version number of both .NET Framework 4.0 and 4.5 are the same: v4.0.30319, so this article is true for both versions.
Also, if you create and compile a project against .NET 4.5 and deploy it to a server that does NOT have .NET 4.5 installed, runtime will fail with an error similar to:
The 'targetFramework' attribute currently references a version that is later than the installed version of the .NET Framework.

Using .NET 4.0 in K2 4.6.5

In K2 4.6.5 the following .NET frameworks are supported:

Component .NET 3.5 Framework SP1 .NET 4 Framework .NET 4.5 Framework
K2 Setup Manager *    
K2 Server   * *
K2 Database * *  
K2 Studio * * *
K2 Designer for Visual Studio * * *
K2 Designer for SharePoint *    
K2 for Reporting Services * *  
K2 Workspace *    

Using .NET 4.0 in K2 4.6 or later

  1. Change the supportedRuntime node in the K2HostServer.exe.config file on the K2 Server (usually located at C:Program Files (x86)K2 blackpearlHost ServerBin) to
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0.30319" />
    </startup>
  2. Change the following key in the K2Server.config file (usually located at C:Program Files (x86)K2 blackpearlHost ServerBinK2Server.config) to
    <Framework Version="v4.0.30319" />
  3. Change the following key in the K2Server.setup file (usually located at C:Program Files (x86)K2 blackpearlHost ServerBinK2Server.setup) to
    <Framework Version="v4.0.30319" />
  4. Restart the K2 service
  5. If necessary, update existing K2 projects as described in the Change the target framework in Visual Studio 2010 and rebuild section.

Using .NET 4.0 in K2 4.5

To host the .NET Framework 4.0 by the K2 Server, you will need to add a key as follows.

  1. Change the following key to the <appSettings> section of the K2HostServer.config file (usually located at C:Program Files (x86)K2 blackpearlHost ServerBinK2HostServer.config)
    <add key="netfxversion" value="v4.0.30319" />
  2. Change the following key to the K2Server.config file (usually located at C:Program Files (x86)K2 blackpearlHost ServerBinK2Server.config)
    <Framework Version="v4.0.30319" />
  3. Change the following key to the K2Server.setup file (usually located at C:Program Files (x86)K2 blackpearlHost ServerBinK2Server.setup)
    <Framework Version="v4.0.30319" />
  4. Restart the K2 service
  • You will be running in .NET 4.0 host, but will still execute .NET 3.5 code.
  • Although you can utilize .NET 4.0 based code constructs and references, you will not be able to use WF 4.0 activities at this time.

Change the target framework in Visual Studio and rebuild

  1. If you are using an existing project, under the Project menu > Properties, you can change the Target Framework Version:
    frameworkversion1.png
  2. If you are creating a new project, change the target framework in the New Project window:
    frameworkversion2.png
     

 

 

 

Console Applications

An error may occur when starting a process instance via a console application created for .NET Framework 4 when referencing the SourceCode.Workflow.Client assembly where the assembly runtime version is v2.0.50727.

Error Example

  1. Create a Console Application that uses the .NET Framework 4 as the Target framework.
    Image
  2. The following sample code shows a simple console application that will demonstrate the issue:
    Image
  3. The Project app.config file will contain the following supportedRuntime version node:
    Image
  4. In your console application create a reference to the SourceCode.Workflow.Client component
    Image
  5. Run the console application and you may see a 'Mixed mode assembly is built against version 'v.2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.' error, such as the following:
    Image

Workaround

  1. Edit the project app.config file and add the following entry [useLegacyV2RuntimeActivationPolicy=”true”]:
    Image
  2. For .NET 4.5, the sku should be: sku=".NETFramework,Version=v4.5"/>
  3. Now recompile and run the console application
    Image

 


0 replies

Be the first to reply!

Reply