Error adding ChromiumWebBrowser to project - C# Visual Studio - c#

I am trying to add the Cef.WinForms library to my project and I'm following the steps found here
https://tutorialslink.com/Articles/DEVELOPING-CHROMIUM-BASED-BROWSER-IN-Csharp/1468. I was able to add the library find using Nuget, however I did get a warning that it expected .NET 4.6.1 and I have .NET 5.0. I tried to manually install 4.6.1 but it will not allow it as it says a newer version is already installed. This may not even be the cause of my error but I wanted to mention it just in case.
When I try to drag the component ChromiumWebBrowser over to my main form, I get the error seen below. I've searched for this error to try and resolve it but I am so far not finding anything helpful. Does anyone know what I'm missing here?

As noted in the comments, when targeting .Net 5.0 you'll need to use the packages with the NETCore suffix.
For .Net Core 3.1/.Net 5.0+
https://www.nuget.org/packages/CefSharp.WinForms.NETCore/
https://www.nuget.org/packages/CefSharp.Wpf.NETCore/
https://www.nuget.org/packages/CefSharp.OffScreen.NETCore/
NOTE A minimum of .Net Core 3.1 is required.
For the .Net 4.5.2 to .Net 4.8
https://www.nuget.org/packages/CefSharp.WinForms/
https://www.nuget.org/packages/CefSharp.Wpf/
https://www.nuget.org/packages/CefSharp.OffScreen/
All packages require Microsoft Visual C++ 2019 or greater.
Ijwhost.dll
To support C++/CLI libraries in .NET Core/.Net 5+, ijwhost was created by Microsoft as a shim for finding and loading the runtime. All C++/CLI libraries are linked to this shim, such that ijwhost.dll is found/loaded when the C++/CLI library is loaded. It's important this dll is distributed with your application.

Related

Upgrading class library project to .net standard 2.1 where this has been referenced by .net framework 4.X projects

We are upgrading our solution of multiple projects. Starting with one class library which is been referenced by 13 projects. I need to upgrade my class library project .NET Framework 4.5 to .NET Standard 2.1.
Here the problem is:
This class library is being referenced by projects of .NET Framework 4.5 and its throwing error that it can't access .NET Standard 2.1 lib
Project 'abc.csproj' targets 'netstandard2.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.5'.
How to resolve this problem? Upgrading all those 13 projects is not possible at the same time.
EDIT:
Following comments, if I convert lib to .netstandard1.1 then errors start coming in the library itself:
After downgrading lib to .netstandard1.1, following on
NetStandard 1.4 does not allow decorating class with [DataContract]. I saw this post and added this package System.Runtime.Serialization.Primitives:
I even added reference to older dll but, still getting error:
Adding answer as we've iterated through the comments. At first OP wanted to change framework of library to .NET Standard 2.1 while having other apps under .NET Framework 4.5.
Unfortunately, this is not possible. As specified in the official documentation, .NET Standard 2.1 is not following along with .NET Framework. Latest you can get is .NET Standard 2.0 with .NET Framework 4.6.1. Solution for this issue is to downgrade common library project to .NET Standard 1.1, other app projects should be able to link to this.
Next iteration (after downgrading to .NET Standard 1.1) brought issue related to "unknown classes" and VS/compiler asking for adding reference. There was already existing question, answer is to download NuGet package related to the data serializers.
If your code in end-applications are also using classes/attributes from the affected assembly, you must make a cleanup. So that all code references the only single version of source. It is not possible to have one Attribute taken from Nuget and check for "same attribute/same name" but from different source (system assembly -> System.Runtime.Serialization).

Problems referencing a Net Standard GDAL library from Net Framework

I have a .Net Standard 2.0 libray using Gdal.Core 2.3. I can reference it successfully from a Net5 project, but I get a "Gdal.Core dll not found" error if I reference it from a Net Framework4.7.2. If I manually add the Gdal.Core.dll to the Framework project I get a "Unable to find an entry point named 'CSharp_OSGeofGDAL_AllRegister___'" error.
I have tried using the standard GDAL library on the Framework project and the Gdal.core package on the .Net Standard class. Also, I have also changed different versions, created minimal projects and did a lot of testing, but I am not able to make it work. Any advice
I finally realized I had the same issue with all libraries referenced on the Standard project and not only GDAL. This problem was related with the way Nuget packages are handled in the old .Net Framework and the .Net Standard. The solution is to migrate from the old Nuget.confi system, to the new PackageReference system used in .Net Standard.

Dafny 3.0 C# dll library problem from 3.0 to 3.2

The problem I have is the following: we have a series of functions, methods and datatypes in Dafny and with it we generate a c# dll library. In order to make use of those libraries, we have added them as a reference to a visual studio c# console application project.
The problem I have is that these libraries refer to a dependency to System.Private.CoreLib. The only place I have found this library is in the source code of dafny. By adding it as a reference, it becomes "incompatible" with all System.* libraries imported by default in c#. This makes it unable to create a class, method etc. Attached are screenshots of the problems I just mentioned.
Finally, if I compile these libraries with Dafny 2.0 (deprecated), I don't have this problem, but I would like to work with the latest version of dafny.
Thank you in advanced.
System.Private.CoreLib is part of the .NET Core runtime and doesn't have to be referenced directly. That's where the basic built-in types like Array, DateTime, Thread etc live. It's used implicitly by all .NET Core projects and doesn't have to be referenced explicitly.
The Dafny 3.0 release notes explain that the tooling migrated to .NET (Core) 5 from Mono and the .NET 5 version of Coco/R is used now
Tool
Migrate to .NET 5.0.
If you used to use mono Dafny.exe to run Dafny before, use dotnet Dafny.dll now.
Implementation
Use .NET 5.0 version of Coco/R.
Your projects will have to target .NET (Core) 5 as well.

Dynamic Link Library, Solution can't load assembly

Recently I started learning how to create Dynamic Link Libraries in Visual Studio with C#.
I followed online instructions on how to create DLLs:
https://learn.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio
http://www.c-sharpcorner.com/UploadFile/1e050f/creating-and-using-dll-class-library-in-C-Sharp/
https://blogs.msdn.microsoft.com/benjaminperkins/2017/04/13/how-to-make-a-simple-dll-as-an-assembly-reference-just-for-fun/
After completing these steps, I tried to add my .dll file to my projects.
On execution I receive this message:
System.IO.FileNotFoundException: 'Could not load file or assembly
'MySql.Connect, Version=1.0.0.2, Culture=neutral, PublicKeyToken=null'. The
system cannot find the file specified.'
I selected .NET Framework 4.6.1 when I started my project. The target framework in the Properties file under the Application tab is selected as .NET Framework 2.0.
The project that should reference to the file is targeting the .Net Core 2 Framework.
I've been at this problem for nearly a week and searched for online solutions.
Any help will be greatly appreciated.
You need to put the DLL somewhere that the runtime can find it. The easiest thing to do would be to put it in the same directory as the .exe, but you have other options as well (see How the Runtime Locates Assemblies).
It is important to carefully decide what platform you intend to use your DLL with.
I selected.NET Framework 4.6.1 when I started my project.
If you mean when you started your DLL project, then you have limited the types of applications that can consume this DLL to .NET Framework 4.6.1+.
Properties file under the Application tab is selected as .Net Framework 2.0.
If I understand correctly, you changed the DLL target from .NET Framework 4.6.1 to .NET Framework 2.0. This widens the compatibility so that the consuming library can be .NET Framework 2.0+. However, this is at the expense of all of the newer features of the .NET Framework.
Do note that official support (i.e. patches) for .NET Framework 2.0 has been gone for several years, and newer machines aren't likely to have it installed.
The project that should reference to the file is targeting the .Net Core 2 Framework.
Here's the crux of your issue. .NET Core ain't .NET Framework. It is a completely different platform.
That said, .NET Core has some limited support for referencing .NET Framework assemblies, but is it sure not to work with .NET Framework 2.0 (which again, hasn't been supported in years). Also, this "compatibility mode" probably means you lose cross-OS support, which is one of the main benefits of .NET Core.
Option 1
So, the knee jerk answer is to make your DLL target .NET Core if you want to use it with .NET Core applications.
Option 2
However, there is also an option to make a portable DLL that works with .NET Framework 4.5+ and .NET Core - make your DLL target .NET Standard.
See How to port from .net framework to .net standard for instructions on changing your DLL to target .NET Standard.

easiest way to convert .NET project from 4.5 to 4.0?

I have a .NET application that I built in 4.5, which has references to a bunch of libraries that were built in 4.5, which themselves have references to 4.5, etc. A user group that I'm trying to distribute the application to is having problems running the executable because they have 4.0 installed; in particular, they're getting a MissingMethodException:
Method not found: 'System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)'.
Because we may have trouble getting each user upgraded to 4.5 (as none of them have admin permissions on their machines and this would require a separate upgrade request for each user), I'm looking at finding an easy way to rebuild the project as 4.0. This seems to require that I rebuild every library and its referenced libraries in 4.0; is there an easier way to do this than going through each library one by one and building a 4.0 version? I'm thinking maybe like a one-click option for "Rebuild all referenced libraries in target framework" or something like that.
If you have dependencies on .Net 4.5 DLLs then you will need to also get .Net 4.0 versions of those if you want to successfully downgrade your project. A .Net project can only reference .Net DLLs up to the same version of .Net as the referencing assembly.
The easiest way to do this is to use something like NuGet to manage your dependencies. Note that when you change the target framework version of your project in VS you will need to uninstall and re-install dependencies with NuGet as NuGet does not automatically do this for you when you change the target framework version.
Of course if all the dependencies are to your own code and you aren't publishing this through a dependency management system like NuGet you will need to downgrade all your other code to .Net 4.0 as well
When I use Visual Studio, I right click on the project, change the framework, fix the References and recompile. Usually straight forward.
Please, have a look at this MSDN page to correctly switch your project to a lower target framework without problems! It is a little bit outdated for what concerns versions, but the process is the same described!
This is based on my experience. I had an application initially created in .net framework 4.5 but I wanted to convert it in .net framework 4.0. I created new project initially created 4.0 and then I did copy and paste of all the forms and controls of my previous application and it works. Framework 4.5 is using Aero2 and 4.0 is Aero... Good Luck :)

Categories