I can't get Transaction Result with QBitNinjaClient - c#

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.

Related

Kusto Connection with cluster using C# {kusto.data}

I'm trying to establish connection to Azure DataExplorer cluster using C# ..
I referenced the C# in https://learn.microsoft.com/en-us/azure/kusto/api/netfx/about-kusto-data
and installed nuget package kusto.data in visual studio and copied the code and did dotnet run in cmd prompt, but it didn't work.
Below is my code-
using Microsoft.Azure.Management.Kusto;
using System;
namespace LensDashboradOptimization
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
//var clusterUrl = "https://masvaas.kusto.windows.net";
//var kcsb = new Kusto.Data.KustoConnectionStringBuilder(clusterUrl);
//Console.WriteLine(kcsb);
// Read the first row from reader -- it's 0'th column is the count of records in MyTable
// Don't forget to dispose of reader when done.
var client = Kusto.Data.Net.Client.KustoClientFactory.CreateCslQueryProvider("https://masvaas.windows.net/Samples;Fed=true");
var reader = client.ExecuteQuery("MyTable | count");
Console.WriteLine(reader);
}
}
}
I tried both fed=true and WithAadUserPromptAuthentication(); both didn't work. Am I missing something?
Hello and welcome to Stack Overflow!
I tried and faced a similar error when I was checking this out. But the issue turned out to be with the version of .Net Framework that I was running. The Kusto.Data package requires .Net Framework 4.6.2 as a dependency. When I had that installed, I was able to install and import the package, and also subsequently connect to the intended Kusto cluster and read data. This is the snippet that worked for me:
using System;
using Kusto.Data;
namespace hello_world
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var client = Kusto.Data.Net.Client.KustoClientFactory.CreateCslQueryProvider("https://help.kusto.windows.net/Samples;Fed=true");
var reader = client.ExecuteQuery("StormEvents | sort by StartTime desc | take 10");
}
}
}
Please double check on the dependencies and let me know if you still run into issues. Hope this helps!
using Kusto.Data;
using Kusto.Data.Common;
using Kusto.Data.Net.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Only these using statement do the job that you are trying to. For that all you need to install SDK from nuget gallery .
Also, only install Microsoft.Azure.Kusto.Data and Microsoft.Azure.Management.Kusto from above. That is sufficient.
Hope this help.
Few more things you can look on as: 1) Static IP 2)VS 2019 community edition with Azure dev packages installed
WithAadUserPromptAuthentication, this method is not supported now as kusto database first need authentication for the user. and the console application is not able to open a prompt window. I recommend to use a web application.

Cosmos not showing up for me

I've been searching for a few hours for a solution for my problems. But I've downloaded Cosmos (operating system) using visual studio 2015 community edition. At first I downloaded the userkit, then realized that I wanted the devkit (maybe). All the examples I see online are using this:
using Cosmos.Compiler.Builder;
But that isn't working for me. ( I did change the properties to use the 3.5 framework, i read that I must use that and now it's not finding Cosmos anywhere. Before when I was using framework 4.5 I could use cosmos, but only Cosmos.System and one other. Any ideas on what I'm doing wrong?
This is what I'm getting in Kernel.cs when I first start a cosmos project:
using System;
using System.Colletions.Generic;
using System.Text;
using Sys = Cosmos.System;
namespace CosmosKernel1
{
public class Kernel : Sys.Kernel
{
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
}
protected override void Run()
{
Console.Write("Input: ");
var input = Console.ReadLine();
Console.Write("Text type: ");
Console.WriteLine(input);
}
}
}
First make sure that you have a COSMOS PROJECT and not a typical c# console app or something.
Second, after confirming that, make sure you have cosmos.compiler and all the cosmos dlls in your references.
Tutorial: https://www.youtube.com/watch?v=oKW3BrclAUY

How can I use PowerShell to install this service fabric project?

I have the following folder structure once I package my Service Fabric NS1.NS2.MicroServicesTest project (written in C#, using .NET):
pkg
|-NS1.NS2.MicroServicesTest.MicroServiceA
|-NS1.NS2.MicroServicesTest.MicroServiceB
|-NS1.NS2.MicroServicesTest.MicroServiceC
|-NS1.NS2.MicroServicesTest.MicroServiceD
|-ApplicationManifest.xml
I am trying to deploy this package using the following PowerShell script:
Copy-ServiceFabricApplicationPackage pkg -ImageStoreConnectionString file:C:\SfDevCluster\Data\ImageStoreShare -ApplicationPackagePathInImageStore NS1.NS2.MicroServicesTest
Register-ServiceFabricApplicationType NS1.NS2.MicroServicesTest
New-ServiceFabricApplication fabric:/NS1.NS2.MicroServicesTest NS1.NS2.MicroServicesTest 1.0.0
It fails on the last command, New-ServiceFabricApplication, with the following error:
New-ServiceFabricApplication : Application type and version not found
Where have I gone wrong? I have tried to follow this tutorial, albeit it kind of uses a base case in its example, whereas my project has 4 microservices as part of it, and an odd naming convention, which makes it even more confusing...
Edit: When I run the Get-ServiceFabricApplicationType command, I see:
ApplicationTypeName : MicroServicesTestType
ApplicationTypeVersion : 1.0.0
DefaultParameters : { "MicroServiceA_InstanceCount" = "-1";
"MicroServiceB_InstanceCount" = "-1";
"MicroServiceC_Endpoint" = "defaultValue";
"MicroServiceC_InstanceCount" = "-1";
"MicroServiceC_MaxRecords" = "100";
"MicroServiceD_InstanceCount" = "-1" }
(from discussion to answer)
After registering it, validate that your Application Type shows up when calling 'Get-ServiceFabricApplicationType'
Check your Application Type version 1.0.0?
Try using this command: New-ServiceFabricApplication fabric:/ MicroServicesTestType MicroServicesTestType 1.0.0

How do I use the Mono.CSharp interpreter in Microsoft.NET

I was under the impression Mono's compiler was usable in Microsoft.NET
edit: updated blog posting here that I originally missed that explains some of it (is consistent with Justin's answers)
I created a simple class to try to use it
[TestFixture]
class Class1
{
[Test]
public void EXPR()
{
Evaluator.Run("using System;");
int sum = (int)Evaluator.Evaluate("1+2");
}
}
And a project in Visual Studio 2010 that references C:\Program Files (x86)\Mono-2.10.1\lib\mono\4.0\Mono.CSharp.dll.
However when I try to run this task I get the following exception, thrown at the Evaluator.Run call:
System.TypeInitializationException was unhandled by user code
Message=The type initializer for 'Mono.CSharp.Evaluator' threw an exception.
Source=Mono.CSharp
TypeName=Mono.CSharp.Evaluator
StackTrace:
at Mono.CSharp.Evaluator.Run(String statement)
at Experiments.Class1.EXPR() in W:\Experiments\Class1.cs:line 16
InnerException: System.TypeLoadException
Message=Method 'Mono.CSharp.Location.ToString()' is security transparent, but is a member of a security critical type.
Source=Mono.CSharp
TypeName=Mono.CSharp.Location.ToString()
StackTrace:
at Mono.CSharp.Evaluator..cctor()
InnerException:
A google confirms one other person asking this question but no answer. I tried to start reading the microsoft article on security transparent code but got confused quite quickly. Would someone be able to suggest a quick workaround to allow me to use this? And possibly summarise the security implications, if any, to me (in the context of my situation - in the future I hope to package it with a thick client application, to be used both internally and by end-users)
It has worked under .NET since April of last year.
Small point but I notice you are missing a semi-colon in your expression for sum.
int sum = (int)Evaluator.Evaluate("1+2;");
I only have Mono 2.11 (from git) at the moment and they have changed to using a multi-instance version of the compiler instead of the static version. So, my code looks a little different:
using System;
using Mono.CSharp;
namespace REPLtest
{
class MainClass
{
public static void Main (string[] args)
{
var r = new Report (new ConsoleReportPrinter ());
var cmd = new CommandLineParser (r);
var settings = cmd.ParseArguments (args);
if (settings == null || r.Errors > 0)
Environment.Exit (1);
var evaluator = new Evaluator (settings, r);
evaluator.Run("using System;");
int sum = (int) evaluator.Evaluate("1+2;");
Console.WriteLine ("The sum of 1 + 2 is {0}", sum);
}
}
}
EDIT: I guess I should confirm that I did in fact successfully execute this on .NET 4 (using Visual C# Express 2010 on Windows XP)
EDIT AGAIN: If you have Visual Studio, you can download the latest version of Mono.CSharp and compile it yourself. There is a .sln (solution file) included with the source so you can build it on Windows without Mono. The resulting assembly would run the code above. Miguel has a post explaining the new Mono.CSharp here.
FINAL EDIT: I uploaded the compiled Mono.CSharp.dll assembly that I actually used here. Include it as a reference to compile the code above.
It looks like this is a bug in Mono.
.NET 4 abandoned Code Access Security but kept the concept of Security Transparent Code. In a nutshell, low-level code that does stuff, like call unmanaged code, must be "security critical". Application level code is marked "transparent". "Transparent" code cannot call into "security critical" code.
It sounds like Mono.CSharp.Location.ToString() needs to be marked with the [SecuritySafeCritical] attribute if you want the Mono 2.10 code to work with .NET 4. Maybe even better would be marking all of Mono.CSharp as SecuritySafeCritical.
http://msdn.microsoft.com/en-us/library/system.security.securitycriticalattribute.aspx
PS. Sorry to have multiple answers for one question. After I realized that 2.11 would work, I became more curious about what the error with 2.10 meant. I cannot really combine this answer with the others.
I decided I should have kept the code more like the question but I did not want to overwrite my previous answer:
The code below works with version 2.11 of Mono.CSharp (available here including a solution file for building with Visual Studio/.NET). It was tested with .NET 4 on Windows XP. I do not have access to Mono 2.10 at the moment.
[TestFixture]
class Class1
{
private Evaluator evaluator;
public Class1()
{
var report = new Report(new ConsoleReportPrinter());
evaluator = new Evaluator(new CompilerSettings(), report);
}
[Test]
public void EXPR()
{
evaluator.Run("using System;");
int sum = (int)evaluator.Evaluate("1+2;");
}
}
EDIT: I uploaded the Mono.CSharp.dll assembly that I actually used here. Include it as a reference to compile the code above.

How to register a service with Mono.ZeroConf?

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.

Categories