I have tried creating an adaptive card, parsing it from json. As mentioned in https://learn.microsoft.com/en-us/adaptive-cards/create/libraries/net#example-parse-from-json, I have installed AdaptiveCards package and tried using that function, but it throws a error like 'AdaptiveCard' does not contain a definition for 'FromJson'.
As there is a Breaking changes from v0.5:
Package renamed from Microsoft.AdaptiveCards to AdaptiveCards
It seems that you have installed Microsoft.AdaptiveCards but AdaptiveCards.
To install AdaptiveCards, please mark Include prerelease checkbox in NuGet package manager:
Apparently the documentation is outdated. The class is named AdaptiveCard now, without the last 's'.
So instead of:
var parseResult = AdaptiveCards.FromJson(card);
Use:
var parseResult = AdaptiveCard.FromJson(card);
Related
E.g.
netstandard2.0 (from Supported target frameworks) which is used as <TargetFramework> in *.csproj files or as folder name in NuGet packages internal structure,
and
.NETStandard,Version=v2.0 which is accepted by System.Runtime.Versioning.FrameworkName class's constructor or can be a value of TargetFrameworkAttribute.FrameworkName.
How to convert those strings from one form to another? At least one (any) direction.
You can use the source code of NuGet.Frameworks:
Here is the method that converts TFM to FrameworkName:
https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Frameworks/NuGetFrameworkFactory.cs#L575
(e.g. netstandard2.0 to .NETStandard,Version=v2.0)
UPDATE #1
The good news is that it is available as a NuGet package:
https://www.nuget.org/packages/NuGet.Frameworks/
Here is a .NET 6 Console Application:
using NuGet.Frameworks;
using System.Runtime.Versioning;
var tfmNetstandard20 = NuGetFramework.ParseFolder("netstandard20");
var fwNetstandard20 = new FrameworkName(tfmNetstandard20.DotNetFrameworkName);
Console.WriteLine(tfmNetstandard20);
Console.WriteLine(fwNetstandard20);
The output will be:
.NETStandard,Version=v2.0
.NETStandard,Version=v2.0
I am using VS 2022, .Net 6.0, and trying to build my first app using System.CommandLine.
Problem: when I build it, I get an error
The name 'CommandHandler' does not exist in the current context
The code I'm trying to build is the sample app from the GitHub site: https://github.com/dotnet/command-line-api/blob/main/docs/Your-first-app-with-System-CommandLine.md , without alteration (I think).
It looks like this:
using System;
using System.CommandLine;
using System.IO;
static int Main(string[] args)
{
// Create a root command with some options
var rootCommand = new RootCommand
{
new Option<int>(
"--int-option",
getDefaultValue: () => 42,
description: "An option whose argument is parsed as an int"),
new Option<bool>(
"--bool-option",
"An option whose argument is parsed as a bool"),
new Option<FileInfo>(
"--file-option",
"An option whose argument is parsed as a FileInfo")
};
rootCommand.Description = "My sample app";
// Note that the parameters of the handler method are matched according to the names of the options
rootCommand.Handler = CommandHandler.Create<int, bool, FileInfo>((intOption, boolOption, fileOption) =>
{
Console.WriteLine($"The value for --int-option is: {intOption}");
Console.WriteLine($"The value for --bool-option is: {boolOption}");
Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}");
});
// Parse the incoming args and invoke the handler
return rootCommand.InvokeAsync(args).Result;
}
I have installed the latest version of System.Commandline: 2.0.0-beta2.21617.1
SURELY I am just being a big fat idiot in some respect. But I don't see it.
Any insight would be welcomed.
This issue is caused by updating the CommandLine 2.0 Beta 2 package. Add the reference System.CommandLine.NamingConventionBinder to the references to fix the problem. Follow the announcements on command-line-api's GitHub account:
In your project, add a reference to System.CommandLine.NamingConventionBinder.
In your code, change references to the System.CommandLine.Invocation namespace to
use System.CommandLine.NamingConventionBinder, where the CommandHandler.Create
methods are now found. (There’s no longer a CommandHandler type in
System.CommandLine, so after you update you’ll get compilation errors until you
reference System.CommandLine.NamingConventionBinder.)
If you want to continue with the old habits, try using older versions of the System.CommandLine package.
References
Announcing System.CommandLine 2.0 Beta 2 and the road to GA
Think you are missing a using line:
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
I can't swear that's it, but it looks like CommandHandler is defined in a namespace not referenced by a using (in your current code), so System.CommandLine.Invocation may be the key!
According to NewtonSoft's documentation, this code:
string props = "{\"lot\":\"TEST\",\"mhd\":\"2016-06-17\"}";
dynamic json = JsonConvert.DeserializeObject(props);
string s = json.mhd;
should work, but I get a RunTimeBinderException when I try it. I have Micrsoft.CSharp referenced and the compile works (it is a runtime error). I am compiling against .NET 4.0, using NewtonSoft version 7.
I tried accessing as json["mhd"], which works fine.
Am I missing something?
The json object is a JObject, so to get the value you need do:
string s = (string)json["mhd"];
I try this case in Newtonsoft.Json 3.5.8 version ,I get this error.
When I upgrade Newtonsoft.Json package version to 4.5.1 it works .
I think it has bug on older version.
#Candide pointed out what was wrong with your example, but if you still want to use json.mhd syntax and have real dynamic object to work with you can do it.
Try to deserialize it using the ExpandoObjectConverter:
var converter = new ExpandoObjectConverter();
dynamic json = JsonConvert.DeserializeObject<ExpandoObject>(props, converter);
I want to do some very basic code-gen (converting a service API spec to some C# classes for communicating with the service). I found this question that seems to suggest I can call Syntax.CompilationUnit() to create a new CompilationUnityntax, however I'm unable to make this code compile; I can't find a CompilationUnit method on any of the Syntax classes I can find (nor can I locate any docs on this) :(
CSharpSyntaxTree.Create appears to need a CSharpSyntaxNode, but I can't figure out how to create one of them either :/
I'm using VS 2015 RC with the latest Microsoft.CodeAnalysis NuGet package (1.0.0-rc2).
Seems that Syntax is now SyntaxFactory:
var comp = SyntaxFactory.CompilationUnit()
.AddMembers(
SyntaxFactory.NamespaceDeclaration(SyntaxFactory.IdentifierName("ACO"))
.AddMembers(
SyntaxFactory.ClassDeclaration("MainForm")
.AddMembers(
SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName("System.Windows.Forms.Timer"), "Ticker")
.AddAccessorListAccessors(
SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))),
SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName("void"), "Main")
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
.WithBody(SyntaxFactory.Block())
)
)
);
How I can add a tagged value to a package in C#. The EA.Package has no tagged values like EA.Element.
But it is possible to add a tv via GUI, so I think that is general possible.
Solution (thx Geert):
protected EA.Element getElementByPackage(EA.Package eaPackage){
return repository.GetElementByGuid(eaPackage.PackageGUID);
}
A package in the API is both a EA.Package as an EA.Element.
Use the package.Element to access the tagged values for a package.