Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use BackgroundWorker class with .net core?

Tags:

c#

.net

.net-core

I am trying to port a C# console project that works fine on Windows to Linux with .NET Core. I have created a project.json file, run dotnet restore and everything seems to work fine. But when I run dotnet build, I get this message :

The type or namespace name 'BackgroundWorker' could not be found (are you missing a using directive or an assembly reference?)

According to .NET Core API, the class BackgroundWorker seems to exist in System.ComponentModel.

Here's my project.json :

"version": "1.0.0-*",
  "buildOptions": {
  "debugType": "portable",
  "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50"
    }
  }

Am I missing something ?

Thanks !

like image 393
Rylyn Avatar asked Dec 16 '16 18:12

Rylyn


1 Answers

You need to include the System.ComponentModel.EventBasedAsync nuget package as a dependency (not the System.ComponentModel nuget package). If you look at the BackgroundWorker.cs file on GitHub, you can see that it's nested under the System.ComponentModel.EventBasedAsync namespace.

Your project.json would look like this:

  "version": "1.0.0-*",
  "buildOptions": {
  "debugType": "portable",
  "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        },
        "System.ComponentModel.EventBasedAsync": "4.3.0"
      },
      "imports": "dnxcore50"
    }
  }
like image 133
computerallergist Avatar answered Sep 22 '22 05:09

computerallergist