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 !
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"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With