4

I downloaded the .NET SDK for the Froala WYSIWIG HTML Editor. The download link is available here: https://www.froala.com/wysiwyg-editor/docs/sdks/dotnet

Simply download the zip, extract it and open it.

When compiling the solution inside Visual Studio 2019, I don't have any Errors/Warnings. No problem either at runtime.

When opening the exact same solution inside Visual Studio Code, I got some errors when compiling (dotnet build) even if compilation succeed. And no problem at runtime.

The errors are mainly Reference type 'HttpContext' claims defined 'System.Web', but not found

As stated here it may be a problem of targetting 2 different .NET framework versions.

The solution (.sln) is composed as below:

  • src project
  • demo-core project (referencing src project) <--- set as default project
  • demo project (referencing src project) <---- not used because I use demo-core

I was not able to find a solution for this annoying error warning at compilation.

UPDATE 1

src project is targetting the net472;netstandard2.0

demo-core project is targetting the .NET Core 2.0

UPDATE 2

I finally succeed get rid of compilation errors. I simply removed net472 from targetted framework of the src projet and immediately compilation errors disappeared.

What did I have ton conclude ? How this modification impacts Visual Studio Code and why this is not necessary under Visual Studio 2019. Sorry but this is strange to me.

Bronzato
  • 9,438
  • 29
  • 120
  • 212
  • Another reason to hate vscode. vscode seems to love finding moans for the sake of moans.. knowing it work in vs2019 should mean all the references are in there correct. what web version are you targetting? – BugFinder Apr 09 '19 at 09:42
  • I updated the question to respond you about targetted versions. – Bronzato Apr 09 '19 at 10:34
  • Have you installed [Omnisharp](https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger.md) extension? – OlegI Apr 11 '19 at 14:34
  • Yes this extension is installed on my Visual Studio Code. – Bronzato Apr 11 '19 at 18:08
  • @Bronzato Please see my explanation regarding Omnisharp and multiple targeting. I believe this addresses your questions in Update 2. – Michael Petito Apr 15 '19 at 23:46

1 Answers1

0

None of the original sources downloaded from that site (and also verified in github commit history) reference net472; they instead reference net471. I suspect the solution was first tried in Visual Studio 2019 and, not having the .NET SDK 4.7.1 targeting pack installed, an attempt was made to retarget SDK 4.7.2.

Once you do this and re-open the source in VS Code, the Omnisharp extension attempts compilation for the first target framework found due to poor support for multiple target frameworks. In this case, the first found for the src project is net472 (which is important). Note that flipping the order of target frameworks doesn't have any effect.

The error "Reference type 'HttpContext' claims defined 'System.Web', but not found" is now straight-forward to explain. If we look for example in src/Image.cs, we see the following using statements:

using System;
using System.IO;
using System.Collections.Generic;
#if netcore
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.StaticFiles;
#else
using System.Web;
#endif

If the src project is "compiled" by the Omnisharp server using net472, it will import System.Web.HttpContext. The demo-core project in Controllers/FoalaApiController.cs compiled for netcore2.0 instead references Microsoft.AspNetCore.Http.HttpContext. These obviously don't match.

Had Omnisharp selected the proper netcore2.0 target for the src project, then these would have matched. It didn't so you see these errors reported by Omnisharp. You don't see these errors from dotnet build or VS2019 because they properly resolve the correct target framework for the src project.


Here's what I first experienced when I downloaded the source. It's not clear what .NET Core SDK version you're using. When I build the source I see the following error with .NET Core SDK 2.2.100.

error NU1003: PackageTargetFallback and AssetTargetFallback cannot be used together. Remove PackageTargetFallback(deprecated) references from the project environment.

The fix for this error is simple: remove the PackageTargetFallback declaration from the .csproj files. After this, the project compiles without errors / warnings using dotnet build.

I didn't see any other errors in VS Code initially because I too did not have the .NET SDK 4.7.1 targeting pack installed. Consequently, Omnisharp could only compile the src project using netstandard2.0.

Michael Petito
  • 12,891
  • 4
  • 40
  • 54