Migration .Net framework to .NET 6 - class library - dll

During migration of our existing project targeting .NET framework 4.8 we encountered starnge error:
MC1000 Unknown build error, 'Could not find type 'System.Web.PreApplicationStartMethodAttribute' in assembly 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.5\ref\net6.0\System.Web.dll'.'
error message image
Basically we have one big class library targeting net6.0-windows that has been used across multiple different smaller projects.
This class library is compileable as a stanalone porject with no errors, but as soon as we reference it in our WPF project, also targeting same net6.0-windows, we got this error.
Does anyone experiencing sme problem?
Any help appreciated...

Eventually I found that mixing of ASP.NET components together with WinForm or WPF is not allowed anymore. So solution was to split our library file into two separate DLL assemblies each targeting proper SDK.

Related

Calling class library I get the error system.data.sqlclient is not supported on this platform

Here is the setup when I am getting this error:
Project "main" based on Core 3.1 and of type console application. Does not have a reference to System.Data.SqlClient and does not need one.
It calls project "process" also based on Core 3.1 of type class library. Does not have a reference to System.Data.SqlClient and does not need one.
"Process" calls project "service" based on Core 3.1 of type class library. This project needs System.Data.SqlClient and has a reference to a package "System.Data.SqlClient (4.5.1)".
When debugging "main", when it gets to "service", the first time it reference SqlConnection, it errors with message "system.data.sqlclient is not supported on this platform"
Why am I getting this error and how can I fix it.
Note: When I add a refernce to System.Data.SqlClient in project "main" - no error, but of course as "main" does not need System.Data.SqlClient, it should not have one.
When I test "service" using xUnit, no errors, it works OK
Thanks
According to the document:
The Microsoft.Data.SqlClient NuGet package includes a number of DLLs
supporting different .NET targets and different runtime platforms. If
you are getting a PlatformNotSupported Exception when you don't think
you should be, it ultimately means your application is not loading the
appropriate DLL. There could be a number of reasons for this. The
NuGet package structure and infrastructure around referencing and
loading referenced NuGet packages includes logic that allows a package
to contain multiple DLLs which implement support for different .NET
and platform targets. Meaning a different DLL for .NET Framework, .NET
Core, .NET Standard, Windows, Linux, etc. The NuGet infrastructure
will automatically reference and load the appropriate DLL based on
your application's needs.
If your application loads a DLL from a NuGet package directly, it
bypasses all this logic and probably loads the incorrect DLL. The DLL
in the NuGet package under
lib/netstandard2.0/Microsoft.Data.SqlClient.dll is basically the
fallback DLL for any unsupported target and simply throws the
PlatformNotSupported exception for any call. This is a nicer exception
than what you would otherwise get when running on a platform that does
not have a DLL built for it. Ultimately, you want to use the NuGet
package reference infrastructure or you would have to implement all
this target framework and platform support logic yourself when
determining which DLL to load.
Additionally, the NuGet package contains all the dependency
information for the SqlClient library and facilitates the downloading
and referencing of dependencies. If you reference and load an
individual DLL manually, it is up to you to ensure all dependencies
are also available to the SqlClient library.
I suggest you could try to use Microsoft.Data.SqlClient instead. More details about cheat sheet for porting from System.Data.SqlClient to Microsoft.Data.SqlClient, you could refer to this article.

C++/CLI project in C# solution usage

Maybe this header isn't decribe my problem exactly, but...
I have .NET Core console app project which uses C++/CLI project written as a wrapper for native C++ code from same dll.
So, both C# and C++/CLI project are compiled well, but when I run C# project, I get this error:
Could not load file or assembly 'Microsoft.VisualC.STLCLR, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
I checked this file on my disk - I have it installed in many directories on it. I wrote all paths I've found in the PATH enviroment variable, but no effect.
My configuration:
Windows Server 2016, .NET Core 3.1.102, MSVS 2019 16.4.3.
Please, can someone say me the reason of this error and give me a correct solution? Thnxs.
P.S. IF it needs I can add classes and data I use in my code.
P.P.S. I have it works under .NET Framework 4.8, but not .NET Core 3.1
I downloaded Microsoft.VisualC.STLCLR dll from
C:\Windows\Microsoft.NET\assembly\GAC_MSIL
and I put it on my repository and references it on my .net core project it works.
I am having the same error while migrating from .NET Framework 4.8 to .NET 6.
I tried to copy the dll side by side with my binaries but with no success.
Procmon did not even list any read of the DLL (I am an happy user of Procmon for many years).
To bypass the runtime error, I removed uses of the cliext namespace in our C++/CLI code.
In my case, I had to convert code depending on :
#include <cliext\set>
#include <cliext\functional>
#include <cliext\vector>
#include <cliext\algorithm>
The exception occured after a call to a method which was using one of the cliext container.
By chance, the amount of conversion work was minimal.

VS2015 C++ DLL and such with Add Reference

I have three VS2015 projects (DLL, C++ App & C# App)
I created the DLL and targeted v4.5 Framework
I created the C++ Application and targeted the v4.5 framwork and then was able to add reference without an issue.
I create the C# Application and targeted the v4.5 framework and then the Add reference fails with check your assembly or COM message.
Both applications have the DLL project added to the solution.
What else can I check as to why my C# process can't add reference?
Thanks,
Mark
I got around it using PInvode and the C# project didn't need to Add Reference afterall. I had to manually edit out the Precompiled header stuff to force that NotUsing. Thanks for the quick response... just had a quick turn around for my boss. Handed a working Cipher DLL for use with both C++ and C# in his project.

Does Xamarin's Android for Mono support same .NET libraries as Mono?

At a high level, my question is:
Is everything that is supported by Mono on a Linux platform supported by Android.Xamarin on an Android platform?
More information: I am investigating the possibility of porting a complex C# application which was targeting the .NET v3.5 framework onto an Android tablet, and want to confirm my understanding of what is supported in Mono vs what is supported on an Android device.
Mono's Compatibility list does a pretty great job of explaining what features are supported in the Mono architecture. As they so clearly state, mono supports:
Everything in .NET 4.0 except WPF, WWF, and with limited WCF.
However, understanding what is supported in Xamarin for Android is not as easy. I found this topic on Assemblies, which includes a description of the namespaces supported under System.dll
Silverlight, plus types from the following namespaces: [more listed]...
The silverlight reference mentions that System.Windows.Threading is under silverlight, but this doesnt seem to make sense if I simply create a new project.
Here's an example: if I open a new mono project and attempt to access System.Windows.Threading, I cannot access it unless I include a reference to WindowsBase.dll. Moreover, I can only successfully reference WindowsBase.dll from within an "Android Class Library" Project - if I attempt to create an "Android Application" Project and attempt to reference WindowsBase.dll I receive a cryptic compilation error, pasted below.
Error 2 Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'WindowsBase.dll'
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute() C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 720 2 AndoidCtmConnectionTester
So my follow up question is: Why would I get a compilation error when referencing a DLL from an Android Application project, but not an Android Class Library Project
System.Windows.Threading is considered as a part of WPF, so there no intention to make it work in Xamarin.Android.
If you want to reference .NET assembly directly, Xamarin.Android can load only few simple .NET assemblies (and with warning: "The referenced project is targeted to a different framework family (.NETFramework)" )
There is also a big chance that WindowsBase.dll is wrapping some win32 native methods, so it is impossible to run it under Android environment.
So the bad news is that you need to port your code to System.Threading classes.

Why can't my .NET 4.5 project use a DLL compiled for .NET 4? (Both use EF 5)

I have an application that consists of a client-side application and a WebApi website.
My client-side stuff is targetting .NET 4 so that I don't have to insist that users install .NET 4.5. My website, however, is entirely under my control, so I'm targetting .NET 4.5.
There is one shared assembly, which I use for data access. It uses Entity Framework 5.
When I build the client application, the DLL used is version 4.4.xxx, whereas when I build the web application, the DLL is 5.0.xxx.
Up until now, I've been able to run the client application with no problems, and I've also been able to run the web application, again without problems.
However, I've now re-created my web application project from scratch (*), and suddenly I can't run it. I get a YSOD saying "Could not load file or assembly 'EntityFramework, Version=4.4.0.0 ..." at the point where my data-access assembly is first invoked.
Now, it's perfectly clear what that error means - it can't find the v4.4 DLL as used by the data-access assembly - but I don't understand why that's a problem with my new project when it wasn't a problem with my old project. As far as I can see, the same DLLs are referenced in each project.
(*) I should explain why I'm re-creating my project. I originally created the project in VS 2012 RC, and then later upgraded to the release version. Although this supposedly upgraded my project, I've had a few problems with it, and have also noticed some differences v. a newly-created project. So, to be on the safe side - and hopefully circumvent those other problems - I'm re-creating it from scratch.
So, my question: why is this suddenly a problem, and what can I do to resolve it?
Is the code depending on the assemblies set to require the exact version? If so, you will need a publisher policy for the EntityFramework assembly or bindingRedirect for the referencing application (web project).