Error when referring .Net Standard project in Xamarin Android Project - c#

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.

Related

Could not load file or assembly Microsoft.Data.SqlClient, Version=5.0.0.0

Facing following issue after deploying app to azure app service:
Unhandled exception. System.IO.FileNotFoundException: Could not load
file or assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=***********'. The system cannot find
the file specified.
Locally everything works as fine.
Microsoft.Data.SqlClient presented in site/wwwroot
Runtime Stack: Dotnetcore - 6.0
Main app and all class libs on .net6
Server Operating System: Linux
Microsoft.Data.SqlClient presented as reference from Microsoft.EntityFrameworkCore.SqlServer (v.7.0.2)
Tried different kinds of Nuget Packages versions - still have same issue
Tried to install Microsoft.Data.SqlClient (latest version & 5.0.0.0) directly into projects - still the same
The solution for us was to:
Locate the actual DLL file (Microsoft.Data.SqlClient.dll) on the developer's desktop filesystem (easy to find; once you're referenced it using NuGet it gets copied to multiple places)
Add it to the web project (we placed it right in the root)
Mark it (via Properties tool window) as Copy Always
Step 3 results in our .csproj file looks like this:
<ItemGroup>
<None Update="Microsoft.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

Cannot add package reference

I'm building a xamarin.ios app in VS mac. I'm trying to add a certain package, but when I try to add it I get this error
jon#jons-MacBook-Pro-2 helloworld % dotnet add package Ditto
/Users/jon/Desktop/hello-world/helloworld/helloworld/helloworld.csproj(140,5): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/6.0.300/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/6.0.300//Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.
Unable to create dependency graph file for project '/Users/jon/Desktop/hello-world/helloworld/helloworld/helloworld.csproj'. Cannot add package reference.
I have also tried using the Nuget manager and I get this when I try to build the project
/Users/jon/Desktop/hello-world/helloworld/helloworld/MTOUCH: Error MT0009: Error while loading assemblies: /Users/jon/.nuget/packages/ditto/1.1.8/runtimes/win/native/dittoffi.dll. (MT0009) (helloworld)
Any thought??

PrivateFontCollection not found Error in c# (linux)

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.

Nuget package references cause "Could not load file or assembly" ?

There is a recent principle on Nuget package parsing. For details, see how NuGet parses package dependencies. A Microsoft diagram is used to explain:
This time you will choose the most recent package, which is the 2.0 version.
no problem.
One problem I encountered today is that one of my Nuget packages (called Package A current version 1.2.3) originally only supports the version of netstandard 2.0, which is defined in the csproj file.
<TargetFramework>netstandard2.0</TargetFramework>
I have another product, the ECS Nuget package (called Package B version 1.0.0), and Package B needs to reference Package A.
The relationship route is [Package B 1.0.0] -> [Package A 1.2.3]
At this time, the two packages in the program can be used normally.
Later, due to the support of the .net framework, I modified the original package A nuget package and changed it to the following.
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
Package A package generation version is 1.3.2. At this time, I refer to the above two packages and find that the compilation is ok, but I am getting an error at runtime.
I can solve the above problem by upgrading Package B, but why is this error?
Is it because of the use of TargetFrameworks?
I also hope that the big men will give pointers.
When I compare the *.deps.json file, I found something helpful. Here is the first scenario get the following json file:
"aliyun-net-sdk-core/1.3.2": {
"dependencies": {
"Serilog": "2.5.0",
"Serilog.Exceptions": "4.0.0",
"Serilog.Sinks.File": "4.0.0"
},
"runtime": {
"lib/netstandard2.0/aliyun-net-sdk-core.dll": {
"assemblyVersion": "0.0.0.0",
"fileVersion": "0.0.0.0"
}
}
}
Because of the reference to version 1.3.2, however, the CLR can't find the DLL with Version 1.3.2 when loading the assembly, there is only assembly version 0.0.0.0, so the CLR looks for the 1.2.3 version referenced by the original project, but it is not found, so it reports an error.
Clearly understood.
After I make up the miss assembly version of the project, I got the
right result.

ASP.NET Core 1.1 compiling with C# dynamic Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

I'm using Visual Studio 2017 RC and started a new ASP.NET Core project targeting the full .NET Framework.
This line of code will not compile.
dynamic handler = _container.GetService(handlerType);
if (handler == null) _logger.LogError("Can't find handler to handle " + cmd.GetType().Name);
I get the following error
CS0656 Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
After some Googling it looks like this is because I'm missing the Microsoft.CSharp Assembly. There are plenty of people who have stumbled into his issue but not seemingly with .NET Core 1.1.
So I did this Install-Package Microsoft.CSharp and got version 4.3.0. My project still won't build.
If I add an Assembly Reference to Microsoft.CSharp (the GAC'd version) then it Compiles and runs.
Is this a Bug? I would have expected the NuGet package to fix this?
I faced this problem. I resolved this problem for me.
You must install Microsoft.CSharp library to your solution from nuget.
You can use Package Manager Console for install Microsoft.CSharp. For example If you want install Microsoft.CSharp 4.7.0 version, you must run this command on the Package Manager Console:
Install-Package Microsoft.CSharp -Version 4.7.0
Nuget link: Microsoft.CSharp
Just add the reference of Microsoft.CSharp.dll and your error will be removed.
There was a similar problem.
I wanted to create a NetStandartd 2.0 library for the NetFramework 4.6.2 environment that uses a dynamic object and got the error "Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create". This error is caused by the absence of the Microsoft.CSharp library.
By correcting .csproj file I was able to make the correct linking:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0;net462</TargetFramework>
<DependsOnNETStandard>netstandard2.0</DependsOnNETStandard>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
I was getting this problem when trying to implicitly casting type dynamic to object.
var output = new Dictionary<string, object>(); // <- object
foreach(var attribute in attributes)
{
var attr = attribute as IEntityAttribute<dynamic>; // <- dynamic
if (attr != null)
{
output.Add(attr.GetType().Name, attr.Value);
}
}
return output;

Categories