I am using Spectre.Console extension for C# Console Application. And I wanted to use Live-Display module of Spectre.Console but I encoutered following problem:
'AnsiConsole' does not contain a definition for 'Live'
Here is my code, or better say, part of it which contains problem (... are parts which aren't required in sample, so during testing/debugging/modification remove them)
using System;
using Spectre.Console;
...
namespace ConsoleApp2
{
class Program
{
...
static void Main(...)
{
AnsiConsole.Live(Clock())
.Start(ctx =>
{
ctx.Refresh();
Thread.Sleep(1000);
});
...
}
...
public static void Clock()
{
Console.WriteLine(DateTime.Now.ToString());
}
...
}
...
}
Additional information
I installed extension using NuGet package manager with following command: PM> Install-Package Spectre.Console, not with dotnet add package Spectre.Console as indicated in docs, but latter option was unavailable for some reason so I used first.
I am using Visual Studio 2019 Community Edition
I am using .NET Framework 4.7.2
Ok, so thanks to #JonSkeet's and #yaakov's comments, I tried installing latest pre-release version 0.39.1-preview-0.31 instead of latest stable version 0.39 and it worked.
Looks like problem was with versions.
Related
I hope everyone is safe and healthy.
I am new to dot net core application and I have a question regarding command line parser.
I am using a NugetCommand line parser package created by a friend in my console application. This Command line parser has a version attribute which displays the version of the system.I want to use this version attribute to display the version of my console application. For example when I type -v or --version it displays the version of the console application. I do not know how I can use the version attribute from the nuget package.
Any leads or suggestions?
This is my interface :
public interface MyInterface1
{
Version Version { get; }
int Id get; }
string Name { get; }
}
This interface is wrapped in a self-created Nuget package for CommandLine Parser called myspace.commandlineparser.commands
I have installed this nuget package in my project.
So basically the interface is part of the Nuget package.
I want to create a Script Task to load data from MongoDB to SQL Server.
I am using Visual Studio 2017 and target SQL Server version is 2017.
The default target .NET Version of the script task based on the above is 4.5, therefore I got the 2.3 version, which was the latest to target 4.5
In order to get the dlls, I first used NuGet to download the packages and then copied the following dlls:
MongoDB.Driver.dll
MongoDB.Driver.Core.dll
MongoDB.Bson.dll
I followed instructions from here:
http://codeingaddiction.blogspot.com/2011/06/how-to-add-strong-name-to-existing-dll_16.html
In order to produce strong named dlls.
Finally, I added the dlls on GAC on the following path
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
I then created a script task and manually added the 3 dlls.
My test code is the following:
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Core;
using MongoDB.Bson.Serialization;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public override void PreExecute()
{
base.PreExecute();
}
public override void PostExecute()
{
base.PostExecute();
}
public override void CreateNewOutputRows()
{
MongoClient client = new MongoClient("mongodb://dgm-mongodbdev-01.development.dc.opap:27017");
IMongoDatabase database = client.GetDatabase("sportsbetting-staging");
IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("event");
collection.Find<BsonDocument>(null).Limit(3);
Console.WriteLine(collection);
}
}
Trying to build gives the following error:
Severity Code Description Project File Line Suppression State
Error The type 'IAsyncCursorSource<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'MongoDB.Driver.Core, Version=2.3.0.157, Culture=neutral, PublicKeyToken=null'.
MongoDb Core Driver does not have any additional dependencies that I may have missed. For 4.5 version of .NET the only dependency is MongoDB.Bson which is added as a reference.
The only article I have found for SSIS script task is this:
https://arcanecode.com/2014/01/14/importing-mongodb-data-using-ssis-2012/
Which is obsolete because it used the version 1.x of the driver.
Any ideas? The message seems misleading because it seems clear that I am not missing any dependency.
Finally, my answer was provided on the following post:
How to fix "Referenced assembly does not have a strong name" error?
Apparently,
MongoDB.Driver.Core.dll
MongoDB.Driver.dll
Have reference to
MongoDB.Bson.dll
Therefore, the public key token had to be added on the il files before re-assembling
I'm new to C# and I've been researching this error for a long time.
I wanted to use my trained TensorFlow model with Tensorflowsharp in Visual Studio for Mac so I created a .NET console project and installed TensorflowSharp 1.13.0 from nuget.org using the built-in package manager.
However, when I included the following code in Program.cs
using System;
using TensorFlow;
namespace ai
{
class MainClass
{
public static void Main(string[] args)
{
var graph = new TFGraph();
}
}
}
I got this error message:
Unhandled Exception:
System.DllNotFoundException: libtensorflow
at (wrapper managed-to-native) TensorFlow.TFGraph.TF_NewGraph()
at TensorFlow.TFGraph..ctor () [0x00022] in <a8cd6d02fde04a81817b4f25d24a7be9>:0
According to some of the posts that I found, this might states that libtensorflow.dylib is not in bin/Debug/ directory, but when I looked into it I found the file inside.
What am I doing wrong?
My environment setup:
Mac OSX 10.14
Visual Studio for Mac COMMUNITY 7.7.4(build 1)
Target framework: .NET 4.7.1
Thank you so much for any help!
Try change to 64 bit.
This may not correct answer to you. But give a try.
I dont have mac environment. But I tried woth .net core and TensorflowSharp and it works fine.
Same time I tried with .net framework and I also got dll not found issue and BadImageFormatException.
https://github.com/migueldeicaza/TensorFlowSharp/issues/103
https://github.com/migueldeicaza/TensorFlowSharp/issues/103
I'm trying to get pythonnet to work in my .Net Core app running on Linux.
I've made a reference to Python.Runtime.dll (which I got from nuget) in my .Net Core project.
My code is:
using System;
using Python.Runtime;
namespace pythonnet_w
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start");
using (**Py.GIL()**) {
// blabla
}
Console.WriteLine("End");
}
}
}
I get this runtime error:
Unhandled Exception: System.MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder
System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
at Python.Runtime.CodeGenerator..ctor()
at Python.Runtime.DelegateManager..ctor()
at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv)
at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv)
at Python.Runtime.PythonEngine.Initialize()
at Python.Runtime.Py.GIL()
at pythonnet_w.Program.Main(String[] args) in D:\Development\~.Net libraries (3.part)\phytonnet\.Net Core test (phytonnet)\c#\pythonnet_test\Program.cs:line 10
/usr/sbin/pythonnet_w: line 5: 19487 Aborted dotnet "/usr/share/pythonnet_wit/pythonnet_w.dll"
Tried to find a solution in these threads but without any luck:
How do I run a py file in C#?
Call Python from .NET
UPDATE:
I tried to open \pythonnet-master\src\runtime**Python.Runtime.csproj** in Visual Studio to see if I can compile it to .Net or .Core, but I can only compile to .Net framework.
I found this article "How to port from .net framework to .net standard"
Is that what I have to do?
I finally had success by using a self-compiled Python.Runtime.dll as of version 2.4.0. There are two options to create a working DLL:
Remove the other target framework net461 from the respective project file (leaving only netstandard2.0).
Run dotnet build using the appropriate options
For option 2, the following works(in Windows, Mac and Linux):
Clone the pythonnet repo (https://github.com/pythonnet/pythonnet)
In the pythonnet folder, cd src\runtime
Run dotnet build -c ReleaseWinPY3 -f netstandard2.0 Python.Runtime.15.csproj in Windows(in Mac/Linux, replace ReleaseWinPY3 with ReleaseMonoPY3 because the former use python37 and the later use python3.7)
Set DYLD_LIBRARY_PATH in Mac or LD_LIBRARY_PATH in linux(Windows skip):
export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.7/lib
Use the built DLL bin\netstandard2.0\Python.Runtime.dll as DLL reference in your Visual Studio .NET Core project (mine targets netcoreapp2.2, netcoreapp3.1 is also tested ok), e.g. in conjunction with the following code,
using System;
using Python.Runtime;
namespace Python_CSharp
{
class Program
{
static void Main(string[] args)
{
using (Py.GIL())
{
dynamic os = Py.Import("os");
dynamic dir = os.listdir();
Console.WriteLine(dir);
foreach (var d in dir)
{
Console.WriteLine(d);
}
}
}
}
}
You can host the IronPython interpreter right in your .NET application. For example, using NuGet, you can download the right package and then embed the script execution (actually the IronPython engine) right into your application.
Ref:
https://medium.com/better-programming/running-python-script-from-c-and-working-with-the-results-843e68d230e5
I'm trying to write an application that communicates with Visual Studio Team Services, using the Nuget packages listed here.
The example code is directly from Microsoft's official documentation, on same same page the packages are listed, under "Pattern for use". My test code is in a console application, set to version 4.7 of the .net framework (compiled by Visual Studio 2017 15.2(26430.16) Release, but I don't think that matters). The code is identical to Microsoft's example, other than changing the connection url, project, and repo name.
The only Nuget package directly installed (about 30 others are installed as dependencies) is Microsoft.TeamFoundationServer.ExtendedClient.
Install-Package Microsoft.TeamFoundationServer.ExtendedClient
using System;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.WebApi;
namespace vssApiTest
{
class Program
{
const String c_collectionUri = "https://[[redacted]].visualstudio.com/DefaultCollection";
const String c_projectName = "Inspections";
const String c_repoName = "Src";
static void Main(string[] args)
{
// Interactively ask the user for credentials, caching them so the user isn't constantly prompted
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
// Connect to VSTS
VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);
// Get a GitHttpClient to talk to the Git endpoints
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();
// Get data about a specific repository
var repo = gitClient.GetRepositoryAsync(c_projectName, c_repoName).Result;
}
}
}
On the line VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);, a TypeLoadException is thrown (at run-time) with the message:
Inheritance security rules violated by type:
'System.Net.Http.WebRequestHandler'. Derived types must either match
the security accessibility of the base type or be less accessible.
None of the Google search variants I've tried on this error message have returned anything helpful.
Am I doing something wrong, is the example code I'm following wrong, or is there some other issue going on?
The problem was due to a bug introduced in version 4.1.0 of the System.Net.Http Nuget package, as discussed here.
The solution was to update that Nuget package to the latest version (4.3.2 at this time, it may have been fixed in earlier versions also).