c# - target .net framework class library with System.ServiceModel dependency from a .net core application -


it should possible reference .net framework class libraries .net core 2 projects in visual studio 2017 runtime exception when trying reference class library dependent system.servicemodel.

create “console app (.net core)”. visual studio set target framework ".net core 2.0".

create “class library (.net framework)”. visual studio set target framework ".net framework 4.6.1".

reference “system.servicemodel 4.0.0.0” class library. fill class1 in class library following:

public class class1 {     public void test()     {         system.servicemodel.endpointaddress address = new system.servicemodel.endpointaddress("");     } } 

reference class library console app. main method of console app call test method in class1:

class program {     static void main(string[] args)     {         new class1().test();     } } 

build , run. exception thrown test() method tried executed:

system.io.filenotfoundexception occurred hresult=0x80070002
message=could not load file or assembly 'system.servicemodel, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089'. system cannot find file specified. source= stacktrace: @ classlibrary1.class1.test() in c:\users\rth\source\repos\consoleapp2\classlibrary1\class1.cs:line 15 @ consoleapp1.program.main(string[] args) in c:\users\rth\source\repos\consoleapp2\consoleapp1\program.cs:line 11

system.servicemodel not in /bin/debug folder of either project.

i have tried manually copy system.servicemodel /bin/debug folder of console app same error.

how reference class library reference system.servicemodel without getting runtime exceptions?

to make code above working without exception:

  1. update class library (.net framework) class library (.net standard 2.0)
  2. add nuget package system.servicemodel.http (version v4.4.0) class library (.net standard 2.0) dependencies.

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -