[Final update 07.12.2020 23:50 --> for everyone seeking for the anwser]
You are probably adding some nuget package which has in fields DEPENDENCIES .NET Core 3.1. For example Serilog.AspNetCore 3.4.0. In this very example you can include Serilog.AspNetCore 3.2.0 because it has in DEPENDENCIES only .NetStandard 2.0. See more explanation in #Ogglas answer.
There is not enough space on earth to ask the one and only question: "Why, o why Microsoft?":) The message is not clearly correlating issue with the solution - this is the lightest euphemism i am capable of making :)
For me, Blazor is very promising but it is still more a beta version. And not only for me. The startblazoring guys are claiming, that Blazor can be fickle sometimes. And I cannot agree more;) I am keeping finger crossed for it. But I suppose it would be a "ready product" only after .NET 6.0.
[Original Topic]
This is so frustrating :)
I hate errors, when I cannot simply interact and understood where it is coming from. I know, I am ignorant, and If I would pay more attention to "how is the blazor app created" I would understand in eye blink.
But for now it is only frustrating. What is? The error message:
Severity Code Description Project File Line Suppression State
Error NETSDK1082 There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'. TestBlazorAppNoRuntimeError.Client C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets 387
Really, what can you fix here?:D Ehhhhh. I understand that .NET 5 is a "new thing". I understand Blazor is a "new thing" But really? It is really easy to "break" ;) (with a message that is saying nothing)
So what did I do?
Did I create very complicated project with hundreds of thousands of files?
No
Did I add hundreds of thousands of nuget packages.
No
All it takes is to create Blazor Webassembly app and add one nuget package to the shared (common) library (FYI: IdentityServer4 package). That is all folks. Kudos if you would now, that this package specificly is causing this issue (because i found out only by mistake):
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'.
Really, there is a great correlation here: between the error message and the package being added (this was sarcasm if anyone missed it:) )
So if you want to reproduce it create create "Blazor Webassembly":
I don't suppose the options chosen are making the difference. But if this is the case - you can see what option I did choose. Then just add IdentityServer4 nuget package to shared library:
https://www.nuget.org/packages/IdentityServer4/
That is all
If you are too lazy - download this project and check for yourself:
https://ufile.io/751l5wgq
I saw hundreds of SOF topics regarding this message:
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'.
But none of those was so easy to reproduce.
Why I am creating this topic?
Because I did try to implement (by copy-pasting to my solution) what guys did create in Blazor boilerplate here:
https://github.com/enkodellc/blazorboilerplate
At the beginning, by mistake, I've added Identity4 NuGet instead of Identity4.storage and that is why I did observe such behavior (such error) and did correlate this package with this error. When I rolled back from Identity4 to Identity4.storage everything was correct once again. But after that I did a lot of code transfer from this repository. And once I've ended, right now, everything is compiling but once again I have:
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'.
And it is driving me crazy. Maybe you would have some idea, how to find out WHAT is causing this error (exactly the same as previously Identity4 nuget package was causing it)
[UPDATE 06.12.2020 12:30]
The question here is more: "Why is it happening and how to locate package causing the issue" I know that I can second guess what is causing this message to appear.
I did a little investigation. This error is showing in this target:
<ResolveRuntimePackAssets FrameworkReferences="#(FrameworkReference)"
ResolvedRuntimePacks="#(ResolvedRuntimePack)"
UnavailableRuntimePacks="#(UnavailableRuntimePack)"
SatelliteResourceLanguages="$(SatelliteResourceLanguages)"
DesignTimeBuild="$(DesignTimeBuild)">
<Output TaskParameter="RuntimePackAssets" ItemName="RuntimePackAsset" />
</ResolveRuntimePackAssets>
<ItemGroup>
<ReferenceCopyLocalPaths Include="#(RuntimePackAsset)"
Condition="'$(CopyLocalLockFileAssemblies)' == 'true' and ('$(SelfContained)' == 'true' or '%(RuntimePackAsset.RuntimePackAlwaysCopyLocal)' == 'true')" />
</ItemGroup>
so I did google ResolveRuntimePackAssets and found this repo and this file:
https://github.com/dotnet/sdk/blob/release/5.0.2xx/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs and such code:
foreach (var unavailableRuntimePack in UnavailableRuntimePacks)
{
if (frameworkReferenceNames.Contains(unavailableRuntimePack.ItemSpec))
{
// This is a runtime pack that should be used, but wasn't available for the specified RuntimeIdentifier
// NETSDK1082: There was no runtime pack for {0} available for the specified RuntimeIdentifier '{1}'.
Log.LogError(Strings.NoRuntimePackAvailable, unavailableRuntimePack.ItemSpec,
unavailableRuntimePack.GetMetadata(MetadataKeys.RuntimeIdentifier));
}
}
Looks like the code "causing" the issue (this calls for writing down information in message about: unavailableRuntimePack.ItemSpec - it would be so much easier;))
So right now the only thing is to locate what is filling this: UnavailableRuntimePacks property. I don't see any code doing that so it have to be some reflection. I've located this code which is probably doing it:
https://github.com/dotnet/sdk/blob/release/5.0.2xx/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs
And this method:
private void ProcessRuntimeIdentifier(
string runtimeIdentifier,
KnownRuntimePack selectedRuntimePack,
string runtimePackVersion,
List<string> additionalFrameworkReferencesForRuntimePack,
HashSet<string> unrecognizedRuntimeIdentifiers,
List<ITaskItem> unavailableRuntimePacks,
List<ITaskItem> runtimePacks,
List<ITaskItem> packagesToDownload,
string isTrimmable,
bool addToPackageDownload)
{
var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
var knownFrameworkReferenceRuntimePackRuntimeIdentifiers = selectedRuntimePack.RuntimePackRuntimeIdentifiers.Split(';');
string runtimePackRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(
runtimeGraph,
runtimeIdentifier,
knownFrameworkReferenceRuntimePackRuntimeIdentifiers,
out bool wasInGraph);
if (runtimePackRuntimeIdentifier == null)
{
if (wasInGraph)
{
// Report this as an error later, if necessary. This is because we try to download
// all available runtime packs in case there is a transitive reference to a shared
// framework we don't directly reference. But we don't want to immediately error out
// here if a runtime pack that we might not need to reference isn't available for the
// targeted RID (e.g. Microsoft.WindowsDesktop.App for a linux RID).
var unavailableRuntimePack = new TaskItem(selectedRuntimePack.Name);
unavailableRuntimePack.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimeIdentifier);
unavailableRuntimePacks.Add(unavailableRuntimePack);
}
else if (!unrecognizedRuntimeIdentifiers.Contains(runtimeIdentifier))
{
// NETSDK1083: The specified RuntimeIdentifier '{0}' is not recognized.
Log.LogError(Strings.RuntimeIdentifierNotRecognized, runtimeIdentifier);
unrecognizedRuntimeIdentifiers.Add(runtimeIdentifier);
}
}
else if (addToPackageDownload)
{
foreach (var runtimePackNamePattern in selectedRuntimePack.RuntimePackNamePatterns.Split(';'))
{
string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimePackRuntimeIdentifier);
if (runtimePacks != null)
{
TaskItem runtimePackItem = new TaskItem(runtimePackName);
runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageId, runtimePackName);
runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageVersion, runtimePackVersion);
runtimePackItem.SetMetadata(MetadataKeys.FrameworkName, selectedRuntimePack.Name);
runtimePackItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimePackRuntimeIdentifier);
runtimePackItem.SetMetadata(MetadataKeys.IsTrimmable, isTrimmable);
if (selectedRuntimePack.RuntimePackAlwaysCopyLocal)
{
runtimePackItem.SetMetadata(MetadataKeys.RuntimePackAlwaysCopyLocal, "true");
}
if (additionalFrameworkReferencesForRuntimePack != null)
{
runtimePackItem.SetMetadata(MetadataKeys.AdditionalFrameworkReferences, string.Join(";", additionalFrameworkReferencesForRuntimePack));
}
runtimePacks.Add(runtimePackItem);
}
TaskItem packageToDownload = new TaskItem(runtimePackName);
packageToDownload.SetMetadata(MetadataKeys.Version, runtimePackVersion);
packagesToDownload.Add(packageToDownload);
}
}
}
After analysing it, the reason why Identity4 (for example) is causing this issue is because runtimePackRuntimeIdentifier is null and wasInGraph was true :) But what does mean, we have to dig a little bit further. The key thing here is the method GetBestMatchingRid:
public static string GetBestMatchingRid(RuntimeGraph runtimeGraph, string runtimeIdentifier,
IEnumerable<string> availableRuntimeIdentifiers, out bool wasInGraph)
{
wasInGraph = runtimeGraph.Runtimes.ContainsKey(runtimeIdentifier);
HashSet<string> availableRids = new HashSet<string>(availableRuntimeIdentifiers);
foreach (var candidateRuntimeIdentifier in runtimeGraph.ExpandRuntime(runtimeIdentifier))
{
if (availableRids.Contains(candidateRuntimeIdentifier))
{
return candidateRuntimeIdentifier;
}
}
// No compatible RID found in availableRuntimeIdentifiers
return null;
}
So here we see that runtimePackRuntimeIdentifier was null because it was not found on: availableRuntimeIdentifiers. And this variable is defined as:
var knownFrameworkReferenceRuntimePackRuntimeIdentifiers = selectedRuntimePack.RuntimePackRuntimeIdentifiers.Split(';');
So let's see how is it defined (in the code below variable runtimePackForRuntimeIDProcessing is selectedRuntimePack from the above mention)
KnownRuntimePack runtimePackForRuntimeIDProcessing;
if (knownFrameworkReference.Name.Equals(knownFrameworkReference.RuntimeFrameworkName, StringComparison.OrdinalIgnoreCase))
{
// Only add runtime packs where the framework reference name matches the RuntimeFrameworkName
// Framework references for "profiles" will use the runtime pack from the corresponding non-profile framework
runtimePackForRuntimeIDProcessing = selectedRuntimePack.Value;
includeInPackageDownload = true;
}
else if (!knownFrameworkReference.RuntimePackRuntimeIdentifiers.Equals(selectedRuntimePack?.RuntimePackRuntimeIdentifiers))
{
// If the profile has a different set of runtime identifiers than the runtime pack, use the profile.
runtimePackForRuntimeIDProcessing = knownFrameworkReference.ToKnownRuntimePack();
includeInPackageDownload = true;
}
else
{
// For the remaining profiles, don't include them in package download but add them to unavaliable if necessary.
runtimePackForRuntimeIDProcessing = knownFrameworkReference.ToKnownRuntimePack();
includeInPackageDownload = false;
}
But this is as far as I can go. I don't understand without further investigation how this selectedRuntimePack.RuntimePackRuntimeIdentifiers should be defined. This is the key thing here. Clearly for some reasons IdentityServer4 doesn't belong to selectedRuntimePack.RuntimePackRuntimeIdentifiers and this is the answer I am looking for :)
IdentityServer4 4.1.1 (latest version) is dependent upon .NETCoreApp 3.1
https://www.nuget.org/packages/IdentityServer4/
If you create a Blazor WebAssembly App using .NET Core 3.1 it will work in the Server App.
However when using .NET Core 3.1 both Client and Shared uses .NET Standard 2.1 and is therefore not compatible. These error messages are a lot clearar though:
Error Package restore failed. Rolling back package changes for
'BlazorApp.Shared'.
Error NU1202 Package IdentityServer4 4.1.1 is not compatible with
netstandard2.1 (.NETStandard,Version=v2.1). Package IdentityServer4
4.1.1 supports: netcoreapp3.1 (.NETCoreApp,Version=v3.1) BlazorApp.Shared
As I mentioned in this link, it seems there is an issue regarding to the following package. So remove the package from your project and every other project that has been referenced by your Blazor project(right-click on project, choose edit project file then remove the following):
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" />
In my case (and hopefully in yours too) the only use of this package was the get the constant string "Bearer" with the field member JwtBearerDefaults.AuthenticationScheme. So instead of this just simply use "Bearer" string.
I had the same issue while working on a blazor wasm/server/shared projects. In my case, I narrowed down the issue to the project sdk types:
Client.csproj:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
Server.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
Shared.csproj definition causing the issue:
<Project Sdk="Microsoft.NET.Sdk.Razor">
Shared.csproj definition without issue:
<Project Sdk="Microsoft.NET.Sdk">
The client wasm project did not like that the shared one was declared as Microsoft.NET.Sdk.Razor and had to change it to Microsoft.NET.Sdk in order to get rid of the error in the title.
I still need to dig further in to better understand the full differences between those two project types but I hope this can help anyone else facing this issue.
I would like to create my custom dotnet tool and in its implementation, I need to get the list of packages referenced by the project (and the packages they depend on).
From the command line, I can run something like this to get that list:
dotnet list package --include-transitive
I was trying to find how this is implemented in the dotnet sdk repo but the repo is so massive it is very difficult to find anything.
Does anyone have an idea where this is implemented or, even better, can you provide a C# code example on how to get this list in code.
I followed the suggestion from #alexandru-clonțea and tried out the code on github.
In my opinion it actually answers the question correctly.
It involves running dotnet restore on the project and generate a dependency graph file and then reading the file using the NuGet.ProjectModel library.
The core part of the code that reads the dependencies is this:
using System;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NuGet.ProjectModel;
namespace YourNamespace
{
/// <remarks>
/// Credit for the stuff happening in here goes to the https://github.com/jaredcnance/dotnet-status project
/// </remarks>
public class DependencyGraphService
{
public DependencyGraphSpec GenerateDependencyGraph(string projectPath)
{
var tempFile = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var arguments = new[] {"msbuild", $"\"{projectPath}\"", "/t:GenerateRestoreGraphFile", $"/p:RestoreGraphOutputPath={tempFile}"};
try
{
var runStatus = DotNetRunner.Run(Path.GetDirectoryName(projectPath), arguments);
if (!runStatus.IsSuccess)
throw new Exception($"Unable to process the the project `{projectPath}. Are you sure this is a valid .NET Core or .NET Standard project type?" +
$"\r\n\r\nHere is the full error message returned from the Microsoft Build Engine:\r\n\r\n" + runStatus.Output);
return new DependencyGraphSpec(JsonConvert.DeserializeObject<JObject>(File.ReadAllText(tempFile)));
}
finally
{
if(File.Exists(tempFile))
File.Delete(tempFile);
}
}
}
}
I want to use MediaToolkit from Nuget Package Manager and in my test projects, the tool worked fine in VB.NET and C#.NET project. However, when I use it in my real project (which has been upgraded many times to higher version in VB.NET), I am always receiving an error attached screenshot. In my test project and real project, both are in .NET 4.6.
string videoPath = Server.MapPath("~/Video/" + fileUpload.FileName);
var inputVideoFile = new MediaFile { Filename = videoPath };
using (var engine = new Engine())
{
engine.GetMetadata(inputVideoFile);
}
duration = inputVideoFile.Metadata.Duration;
Could you please help me to resolve the issue?
I'm a beginner of C# and blockchain.
I'm studying blockchain with "Programming The Blockchain in C#".
I tried to run this source code following the book:
using NBitcoin;
using QBitNinja.Client;
using QBitNinja.Client.Models;
namespace NBitcoinTest1
{
class Program
{
static void Main(string[] args)
{
// Create a client
QBitNinjaClient client = new QBitNinjaClient(Network.Main);
// Parse transaction id to NBitcoin.uint256 so the client can eat it
var transactionId = uint256.Parse("f13dc48fb035bbf0a6e989a26b3ecb57b84f85e0836e777d6edf60d87a4a2d94");
// Query the transaction
GetTransactionResponse transactionResponse = client.GetTransaction(transactionId).Result;
}
}
}
But it doesn't work because of exception.
It says "Method 'System.Net.Logging.get_On' not found.", so I tried to find "System.Net.Logging", but I couldn't find any package named "System.Net.Logging" in nuget.org.
How can I solve this problem?
Environment: macOS Sierra 10.12.6, Visual Studio for Mac[Community] 7.2(Build 636)
Your problem relies in the conflicting types of NBitcoin dependencies, as you installed NBitcoin first then installed QBitNinja which is installed with NBitcoin also and to my surprise a more up to date version! So delete the first dependency version which was v3. Everything should work then, don't worry i've only started to read it yesterday myself :) It is a community built book so i can expect some errors.
I'm trying to test the ZeroConf sample at http://www.mono-project.com/Mono.Zeroconf.
I'm running OpenSuse 11 and Mono 2.2.
My server code is:
using System;
using Mono.Zeroconf;
namespace zeroconftestserver
{
class MainClass
{
public static void Main(string[] args)
{
RegisterService service = new RegisterService ();
service.Name = "test server";
service.RegType = "_daap._tcp";
service.ReplyDomain = "local.";
service.Port = 6060;
// TxtRecords are optional
TxtRecord txt_record = new TxtRecord ();
txt_record.Add ("Password", "false");
service.TxtRecord = txt_record;
service.Register();
Console.WriteLine("Service registered!");
Console.ReadLine();
}
}
}
But I can't find my registered service with the sample client browser code nor with mzclient.
Thanks!
I've also tried to use the binaries provided at the Mono.Zeroconf project page and building the libs from source for use on Windows and was unable to publish a service that was findable by other clients. I tried both the example code on the site and the MZClient provided.
After a little more digging I found a project that used to the Mono.Zeroconf libs. By using the binaries checked into the Growl for Windows project at Google Code (which appear to be the latest version 0.9.0) I was able to successfully publish a findable service with both the sample code and MZClient.
So an apparent work around would be to grab the binaries (Mono.Zeroconf and Mono.Zeroconf.Providers.Bonjour) from that project and use those instead of the ones provided by the project.
The binaries at mono-project.com/Mono.Zeroconf are out of date and still contain code that causes this problem. The most recent code (with all the fixes) is at this link
but require you to compile the code yourself.
I wasn't able to get a service published either. I looked through the code and there is a bug in Service.cs, the UPort setter:
this.port = (ushort) IPAddress.HostToNetworkOrder((int) value); //overflow, port is always 0
It should be
this.port = (ushort) IPAddress.HostToNetworkOrder((short) value);
Recompiling after updating the source from the following link solved the issue
https://github.com/mono/Mono.Zeroconf/tree/master/src
He is using mzclient to test his Mono.Zeroconf code above. The entire point of Mono.Zeroconf is to provide cross platform, multiple mDNS provider support (Avahi and Bonjour).
There appears to be an issue with the EntryGroup DBus Avahi API and I am looking into it in Mono.Zeroconf. I'll post a solution here, as well as make a new Mono.Zeroconf release (I am the maintainer of the project) when I figure out the issue.