Introduction

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."

Overview

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 you update for the first file depends on which version of K2 you have installed. Refer to the correct version below.

Note that 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 a K2 4.6.5

In K2 4.6.5 the following .NET frameworks are suported:

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 a K2 4.6 or later Configuration

1. Change the supportedRuntime node in the K2HostServer.exe.config file on the K2 Server (usually located at C:\Program Files (x86)\K2 blackpearl\Host Server\Bin\) 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 blackpearl\Host Server\Bin\K2Server.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 blackpearl\Host Server\Bin\K2Server.setup) to

<Framework Version="v4.0.30319" />
4. Restart K2HostServer.exe


Jump to the Change the target framework in Visual Studio 2010 and rebuild section.

Using .NET 4.0 in a K2 4.5 Configuration

 

In order 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 blackpearl\Host Server\Bin\K2HostServer.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 blackpearl\Host Server\Bin\K2Server.config)

<Framework Version="v4.0.30319" />

3. Change the following key to the K2Server.setup file (usually located at C:\Program Files (x86)\K2 blackpearl\Host Server\Bin\K2Server.setup)

<Framework Version="v4.0.30319" />
4. Restart K2HostServer.exe
  • 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 2010 and rebuild

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


 

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

  • Create a Console Application that uses the .NET Framework 4 as the Target framework.
    Image
  • The following sample code shows a simple console application that will demonstrate the issue:
    Image
  • The Project app.config file will contain the following supportedRuntime version node:
    Image
  • In your console application create a reference to the SourceCode.Workflow.Client component
    Image
  • 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

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