PrivateFontCollection not found Error in c# (linux) - c#

I'm using command dotnet build in order to build a game in the MonoGame framework in Ubuntu 20.04 using .NET 5.0.
It was fine in Windows, but now that I'm using it here, it gives me this error:
error CS1069: The type name 'PrivateFontCollection' could not be found in the namespace 'System.Drawing.Text'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. [/home/mrwoto/Ali/Programming/csharp/SAO/SAO/SAO.csproj]
So, is there anyway to resolve it? How can I add a reference to it in .csproj file?

One option is to add it from the terminal with
dotnet add package System.Drawing.Common
After this, you should be able to see something like the following in the .csproj file.
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
Please note that dotnet add is more than just adding some text to csproj.
From dotnet add package:
The dotnet add package command provides a convenient option to add a package reference to a project file. After running the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes, a <PackageReference> element is added to the project file and dotnet restore is run.

Related

The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)

Main Problem
The above is just one of over 1k+ errors in my C# project. I am using a 2017 MacBook Pro with Catalina 10.15.6. and VSCode. The dotnet-SDK I have is 3.1.401. I tried uninstalling and re-installing it but that didn't work. I had a project that was working perfectly then last night I did brew upgrade and today I have all of these errors. Of course I tried dotnet restore dotnet ef database update Those commands succeed in reinstalling the packages to the project directory and re-applying the database migrations (this project uses a postgres database in case that's important), but it still has all of those errors.
I was able to get the project working on Firefox after I re-created a new development SSL certificate.
When I tried to run the app and connect to `https://localhost:5001" like I always do I got this
"Secure Connection Failed
An error occurred during a connection to localhost:5001. PR_END_OF_FILE_ERROR
The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
Please contact the website owners to inform them of this problem."
I fixed this with the following commands dotnet dev-certs https --clean and then dotnet dev-certs https And then it started to work fine on Firefox but I still got those 1k+ errors in VScode.
In Conclusion
The project works, I just have a ton of errors in VSCode and I'm not sure what's causing them.
Error Samples
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
The type 'Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
I had the same issue and the way to solve it for me was:
Install Nuget package Microsoft.AspNetCore.Mvc.RazorPages ( https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.RazorPages/ )
from .net CLI:
dotnet add package Microsoft.AspNetCore.Mvc.RazorPages --version 2.2.5
Change your .csproj file, you have to add AddRazorSupportForMvc, so that it would look like this:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
The main issue is that Microsoft.AspNetCore.MVC namespace no longer exists.
Please try
dotnet dev-certs https --trust
https://www.hanselman.com/blog/DevelopingLocallyWithASPNETCoreUnderHTTPSSSLAndSelfSignedCerts.aspx
The problem was fixed here: https://github.com/OmniSharp/omnisharp-vscode/issues/3990
When my dotnet core sdk updated to 3.1.401 it made it so that I had to change a setting in vscode involving mono.
I went to File > Preferences > Settings then searched "omnisharp use global mono" and changed the resulting value from "auto" to "never." This stopped the errors when linting.
I would like to add that while debugging this issue in your app, look for any occurrence of MVC. I ran into this issue in a Blazor WebAssembly app on .net 5, and discovered the problem was a seemingly innocuous SelectList property, which sits within the Mvc.Rendering namespace, in my shared class library assembly...

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.2.0.0,

I created a .net core 2.2 project using the AWS Lambda function template. Added a MySQL EntityFramework nuget package. My project targets .NET Core 2.2. I have code which uses DbContext and EF stuff. When I run the app using their lambda test tool, I get this error: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.2.0.0, .....
Using Process Monitor, I can see the app is trying to load Microsoft.EntityFrameworkCore.dll from ...\bin\Debug\netcoreapp2.2\Microsoft.EntityFrameworkCore.dll which doesn't exist.
My question is why aren't any of the supporting assemblies in that folder? The only assembly (.dll file) in the folder is my app's.
Following step help you to solve this problem:
Delete all bin and obj folders.
Clean Solution. [Build>Clean Solution].
Rebuild Solution
Try to use some type of Microsoft.EntityFrameworkCore namespace explicitly somewhere in your code. For example:
var _ = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder();
It sould force the build to copy the assembly to result directory.
I have some ideas.
Firstly check, if the folder that you want to refer allows the Visual to have access.
If it do not work, try reinstaling packages through nugget (If I remember correctly I had this same error.). If it shows that its not installed in nugget manager, just install it, even a few times.
Here is the anwser for your question at the end:
Where does NuGet put the dll?
I had a similar problem, in my case removing the line from the .csproj file helped
<PublishReadyToRun>true</PublishReadyToRun>

Error: Could not load file or assembly 'Microsoft.Win32Registry' from .NET Standard Library Consumed by .NET Framework Console App

The Problem
The Microsoft.Win32.Registry nuget package is giving me a lot of issues . We had .NET Framework 4.7.2 library that had a helper class that used that package and worked fine from a .NET Framework 4.7.2 unit test project. We recently converted the library to target .NET Standard 2.0, and now this class breaks when used with the following error:
ERROR: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Win32.Registry, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Win32.Registry, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at NetStandardRegistryLib.RegistryUtil..ctor(String remoteMachineName)
at NetStandardRegistryLib.Program.Main(String[] args) in C:\src\Microsoft.Win32.Registry-IssueRepro\FrameworkRegistry\RegistryEditor\Program.cs:line 21
When I look at output of the Console project, I don't see the Microsoft.Win32.Registry.dll in the output.
Using ILSpy and loading my .exe - it seems it would try to resolve the .dll from my dotnet core installation, which wouldn't work since it's a .NET Framework app.
To Reproduce
I've created a repo that reproduces for me on my Windows 2010 machine. You can find it here: https://github.com/TylerNielsen/Microsoft.Win32.Registry-IssueRepro
Clone the repo, then open and build the RegistryEditor project.
Using Powershell or your favorite editor - call the tool with three required arguments [remoteMachineName] [Environment variable name to set] [Value to set on the environment variable] **
** Note, this actually requires a remote machine you can reference by IP address. For some reason using 127.0.0.1 doesn't work for me, but I'm unsure why. The use case for this utility is for accessing remote machine environment variables.
Other Notes
When I create a .NET Framework Class Library to use for unit tests and reference the same .NET Standard Library - the Microsoft.Win32.Registry package is included and the utility runs just fine.
In your repo, if you look into both csproj files you'll see they are quite different. The NetStandardRegistryLib.csproj is the new format, the RegistryEditor.csproj is the old one.
Your problem is that old style projects do not resolve dependencies transitively. RegistryEditor will not copy dependencies of its own dependency NetStandardRegistryLib.
There are at least two ways to solve your problem:
Just add Microsoft.Win32.Registry Nuget package to RegistryEditor project explicitly. That'll make the Microsoft.Win32.Registry.dll to appear in the RegistryEditor build folder.
Convert the RegistryEditor.csproj to new format. It's not limited to netstandard builds, you can use it for builds targeting .Net Framework versions as well. And it does resolve dependencies transitively!
Here's a long guide for how to do the conversion in general https://natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/
Since your project is quite simple, I've converted it for you. Just replace the content of RegistryEditor.csproj with the code below. It's still targeting net472.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>RegistryEditor</AssemblyName>
<RootNamespace>RegistryEditor</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NetStandardRegistryLib\NetStandardRegistryLib.csproj" />
</ItemGroup>
</Project>
Note that several properties that used to be in AssemblyInfo.cs file are provided by csproj file properties now, so you need to remove them from AssemblyInfo.cs to fix compilation errors:
[assembly: AssemblyTitle("RegistryEditor")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RegistryEditor")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Error when referring .Net Standard project in Xamarin Android Project

I'm getting this error when I add a reference to the .Net Standard project in the Andoid Project.
Severity Code Description Project File Line Suppression State
Error Can not resolve reference: System.Threading.Tasks.Extensions,
referenced by DotNetty.Transport. Please add a NuGet package or
assembly reference for System.Threading.Tasks.Extensions, or remove
the reference to DotNetty.Transport. VFMApp.Droid
I tried:
Neither NuGet packages (System.Threading.Tasks.Extensions / DotNetty.Transport), clean solution, compiled project successfully, reference project, compile: ERROR
NuGet package for DotNetty.Transport, clean solution, compiled project successfully, reference project, compile: ERROR
NuGet package for System.Threading.Tasks.Extensions, clean solution, compile project successfully, reference project, compile: ERROR
Both NuGet packages (System.Threading.Tasks.Extensions / DotNetty.Transport), clean solution, compile project successfully, reference project, compile: ERROR
Packages in .Net Standard project:
Acr.UserDialogs 7.0.1
Humanizer 2.5.16
Microsoft.Azure.Devices.Client 1.18.1
Microsoft.Azure.Mobile.Client 4.1.1
Microsoft.Azure.Mobile.Client.SQLiteStore 4.1.1
NETStandard.Library 2.0.3
Plugin.Share 7.1.1
Refractored.MvvmHelpers 1.4.1-beta
Xam.Plugin.Connectivity 4.0.0.190-beta
Xam.Plugin.DeviceInfo 4.1.0-beta
Xam.Plugin.Geolocator 4.5.4-beta
Xam.Plugin.Media 4.1.1-beta
Xam.Plugins.Settings 4.0.0.10-beta
Packages in Android project:
Xamarin.Android.Support.Compat 28.0.0
Xamarin.Android.Support.Design 28.0.0
Xamarin.GooglePlayServices.Maps 60.1142.1
I was able to get the same error as you when I referenced DotNetty.Transport from a Xamarin.Android project compiling/targeting against API Level 28. It seems to be an issue with System.Threading.Tasks.Extensions v4.5.1 that DotNetty.Transport is referencing. Here is a link to a similar problem from another project:
https://github.com/dotnet/reactive/issues/803
To sum up the issue, it looks like that Systems.Threading.Tasks.Extensions v4.5.1 has an empty profile for MonoAndroid10. Because the profile is empty, it can not resolve the System.Threading.Tasks.Extensions.dll file, thus the error.
To fix this, you have to update your android *.csproj file and redirect the reference to use the System.Threading.Tasks.Extensions.dll that is defined in the netstandard2.0 profile.
I performed the following steps:
Add the System.Threading.Tasks.Extensions v4.5.1 nuget package to your Xamarin.Android project.
Add the System.Runtime.CompilerServices.Unsafe v4.5.2 nuget package to your Xamarin.Android project
Close Visual Studio.
Open your Xamarin.Android *.csproj file with a Text Editor.
Add another <ItemGroup> to tell your project to use the .netstandard2.0 profile instead of the MonoAndroid10 profile
<ItemGroup>
<Reference Include="System.Threading.Tasks.Extensions">
<HintPath>$(UserProfile)\.nuget\packages\system.threading.tasks.extensions\4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
</ItemGroup>
So it should look something like this:
Save the file and reload your project in visual studio. After I did that I was able to compile successfully.

Running DotNet Build Causes Microsoft.Build.Tasks.CodeAnalysis.dll Assembly Conflict

I'm having an issue trying to build a dotnet core project from command line that has these references:
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.6.1" />
<PackageReference Include="Microsoft.Net.Compilers" Version="2.6.1" />
For whatever reason it keeps saying Microsoft.Build.Tasks.CodeAnalysis.dll assembly has already been loaded. Here is the exact error message:
C:\Users.nuget\packages\microsoft.net.compilers\2.6.1\tools\Microsoft.CSharp.Core.targets(84,5):
error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could
not be loaded from the assembly
C:\Users.nuget\packages\microsoft.net.compilers\2.6.1\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll.
Assembly with same name is already loaded Confirm that the
declaration is correct, that the assembly and all its dependencies are
available, and that the task contains a public class that implements
Microsoft.Build.Framework.ITask.
When I go to that project directory and run dotnet build It has no issues building the project, but when I run dotnet build against the solution that's when I get this error. If I build the solution from Visual Studio it also has no issues building. Really strange behavior, not quite sure how to get around it.

Categories