从.NET Framework迁移至.NET Core时System.ServiceModel命名空间不存在ServiceBehaviorAttribute问题求助
Hey there! I’ve dealt with this exact headache when moving WCF services from .NET Framework to .NET Core, so let’s break down how to fix it.
Why this happens
You installed System.ServiceModel.Primitives, which covers basic WCF primitives like channel factories and data contracts—but ServiceBehaviorAttribute lives in a separate, more specific WCF package that handles service hosting and behavior configuration.
Step-by-step solution
Install the correct NuGet package
Depending on your WCF service's binding type, install one of these packages:- For HTTP/REST-based services:
# Package Manager Console Install-Package System.ServiceModel.Http# .NET CLI dotnet add package System.ServiceModel.Http - For TCP-based services:
Install-Package System.ServiceModel.NetTcpdotnet add package System.ServiceModel.NetTcp
These packages include the full service model components, including
ServiceBehaviorAttribute.- For HTTP/REST-based services:
Verify the namespace reference
Make sure your code file has the required using directive:using System.ServiceModel;Once the package is installed, this namespace will resolve
ServiceBehaviorAttributewithout issues.
Quick extra tip
If you’re using other WCF behaviors (like OperationBehaviorAttribute) or hosting-related features, these packages will cover those too. For .NET 5+ and .NET 6+, the WCF NuGet packages are fully optimized for modern .NET, so you won’t run into compatibility hiccups as long as you pick the right package for your binding.
内容的提问来源于stack exchange,提问作者sameera guntimadugu

