简体   繁体   中英

Could not load System.ServiceModel.ServiceBehaviorAttribute in .NET Core project

I have a .NET Core test project. In this, I need to call WebApi and WCF services (as we have migrated only some of our projects and I need to generate test data using old and new services). I have added the System.ServiceModel.Primitives package to the project but I still get this exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeLoadException: Could not load type 'System.ServiceModel.ServiceBehaviorAttribute' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Has somebody an idea what I could have missed?

I found out that there were a lot of missing references in my project, none of them related to WCF directly. When debugging with breakpoints on the exceptions, I added the missing packages one after the other. In some cases, I found online that there is just an exception in .NET Core and you can't do anything for it, and have to just ignore it. Quite strange but at the end my tests were running.

I still have no idea why the exception from the question was occurring but it disappeared once all of the required references were available. Maybe something wan't building correctly before that and so the WCF package wasn't loaded?

Never mind, should you get such a message, just enable breakpoints on all exceptions and debug to see what is really going on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM