3

I have a large number of .NET Framework 4.8 applications. They extensively use System.Web, which is a framework only API. To ease the transition to .NET Core/.NET 5+, I would like to extract some of the functionalities of the framework code into .NET Standard libraries.

This will create the situation where my new core applications are calling standard libraries that may reference framework application code to do their job while that code is not yet updated. Is this even possible? Can standard libraries instantiate framework classes that make use of framework only APIs like system.web?

In my current situation I have 3 classes in three separate projects in 2 solutions.

Solution A
    StandardClass (.NET Standard 2.0)
    TestClass (.NET Core 3.1, MSTest)
Solution B
    FrameworkClass (.NET Framework 4.8)

Solution B builds to a dll that is referenced by Solution A. My TestClass creates an instance of StandardClass and calls StandardClass.Foo().

StandardClass has a property _frameworkClass of type FrameworkClass, initialized in StandardClass's constructor.

StandardClass.Foo() calls _frameworkClass.Bar() and it returns a string, but Bar() uses System.Web.HttpContext throughout the course of it's processes, amoungst other System.Web classes. So when StandardClass.Foo() fires, I get the error that System.Web.HttpContext cannot be loaded from System.Web

I figured that as long as StandardClass does not know about what classes FrameworkClass is using to do its job, then it would be fine.

Austin
  • 105
  • 1
  • 12
  • this should help https://github.com/dotnet/ef6/issues/1571#issuecomment-614708212, anything which can be converted to std should,. but you more likely run into other issues. 4.8 can talk to Standard and standard can talk to 4.8 depending on the supported version. but this isnt really the problem its that most project are not broken down enough as there was never a need. so each case is unique to the level of complexity and work require. PS its always more work than you think.I am the user Seabizkit on Github. – Seabizkit May 26 '20 at 17:02
  • to be clear where is a chart which should help https://learn.microsoft.com/en-us/dotnet/standard/net-standard – Seabizkit May 26 '20 at 17:05
  • I understand that they can talk to eachother, but if my standard library calls say a framework app class that uses system.web, I get errors saying system.web cannot be loaded. Is there some way for the standard app to call the framework app and have the framework use system.web, then return a simple result like a string or int? – Austin May 28 '20 at 18:38
  • give more details about how your project is structured... like lib A, lib B lib C and there versions target frameworks, and their references between them.... try make it a table which is easy to read. then explain what is in what lib and what your attempting to do, the way you describe it, it sound fishy and that's because i have no real idea of what you are working with. The short answer is its mostly not possible but cant say for sure as i don't know what you are actually doing. – Seabizkit May 28 '20 at 19:21
  • I've added a more in depth outline of my classes in a general format. – Austin May 28 '20 at 19:58
  • A Standard assembly may not hold a reference to a Framework-only assembly. Otherwise, it's not a Standard assembly. If it could it would defeat the purpose of the Standard moniker. – Heretic Monkey May 28 '20 at 20:02
  • think about it... it doesn't matter how its loaded... if you not able to convert it then it can not be loaded. how ever if the class is, but then you would be loading the wrong version... aka if you cant convert FrameworkClass to Standard then it can not be loaded. as there will be api references it has no conversion for. https://dotnet.microsoft.com/platform/dotnet-standard, same how you cant reference a 4.7 into a standard 2.0 the link give more info and whats supported. – Seabizkit May 28 '20 at 20:41
  • what you want to do, is extract what you can from 4.7 into a standard lib and then you can use that standard lib in core. Problem is 99% of the time you cant extract what you want to. Largely due to no foresight and not needing to do this type of thing in the past. I myself am going through this extensively. depending on usage, but from my experience you going to run into the same head ache i did. Once option although im not recommending is that wen you start the new std lib.. you can mutli target framework, when extracting common.. so that it builds for 4.7 and std. – Seabizkit May 28 '20 at 20:48

0 Answers0