C++/WinRT console application using c++17 language projection - c++-winrt

I was curious about how I can call .net libraries from a C++ console application using the newer C++/WinRT using C++17 language projections. But I find that it’s hard to find even a hello world example of this.
How would I create an equivalent console application in C++/WinRT as this simple C# hello world program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
class Program
{
static void Main(string[] args)
{
Console.Write("Hello World");
Console.ReadKey();
}
}
}

I guess you need to use c++/cx instead of c++/WinRT, since c++/cx let’s you access .net and c++/WinRT only lets you access the UWP version of .net called runtime components:
#using <mscorlib.dll>
using namespace System;
int main(array<System::String ^> ^args)
{
System::Console::WriteLine("Hello world");
return 0;
}

Related

Build error when using [FromService] decorators in controller with Functions v3

I have created a new projected, where I am trying to use [FromServices] with Microsoft.NET.Sdk.Functions" Version="3.0.13" and "Microsoft.Azure.Functions.Extensions" Version="1.1.0".
There are some tickets opened on this subject. For example this one.
I haven't seen any response/solution from Microsoft.
Is there an incompatibility between libs, what is the combination that I should use?
If this method injection doesn't work, can you please tell me what other alternatives do I have?
Startup.cs
using Azure.Storage.Blobs;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
[assembly: FunctionsStartup(typeof(Startup))]
namespace SubscriptionManager.Functions
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddTransient<IAccountService, AccountService>();
builder.Services.AddScoped<ISubscriptionService, SubscriptionService>();
}
}
}
Thank you!
The .Net version comaptible with "Microsoft.Azure.Functions.Extensions" Version="1.1.0" is .NETStandard 2.0.
Please refer the Document.

SignalR 2.0 The namespace '' already contains a definition for 'Startup'

I tried to follow a tutorial on SignalR 2.0. with ASP.NET MVC 4.0
I build the new Startup class as instructed.
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(MyApp.Startup))]
namespace MyApp
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
app.MapSignalR();
}
}
}
When I tried to build the project. I got The namespace 'MyApp' already contains a definition for 'Startup' .
I have search the whole project and physical folders to find where the second Startup,cs is but I could not find it.
Can anyone share some light on this?
Thanks,
I found the duplicate. It was defined in BundleConfig.cs. Removed it from BundleConfig.cs and it builds fine. Thanks,
Try making your Startup class partial:
public partial class Startup

Can't subscribe to CheckinEvent

I am trying to subscribe to CheckinEvent, for some reason my Notify method isn't called.
This is my contract -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace TFSubscriber
{
[ServiceContract(Namespace = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03")]
public interface IRollupService
{
[OperationContract(Action = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify")]
[XmlSerializerFormat(Style = OperationFormatStyle.Document)]
void Notify(string eventXml, string tfsIdentityXml);
}
}
My implementation is pretty simple, empty method. I put a breakpoint in my Notify method and it's not called.
This how I subscribe to CheckinEvent -
C:\Program Files\Microsoft Team Foundation Server2010\Tools>bissubscribe.exe /eventType CheckInEvent /address http://localhost:4556/Rollupservice.svc /collection http://localhost:8080/tfs/defaultcollection
I have a solution that I added to source control already, and I am checkin' some files and the breakpoint isn't getting hit.
What am I doing wrong?
Are you sure your subscription works? For example try logging some information regarding input parameter eventXML. Because, you need to be sure about if your subscription works or not. If so, you can run your SVC project and attach a debugger on it. That is how debugger supposed to hit your breakpoint.

Trouble setting up RavenDB in embedded mode

I used this as a reference and installed both (using nuget)
Install-Package RavenDB.Client -Version 1.0.992
AND
Install-Package RavenDB-Embedded -Version 1.0.919
(The official link recommends using Install-Package RavenDB-Embedded. But that nuget command fails with the error Install-Package : Unable to find package 'RavenDB-Embedded'.)
But the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client.Document;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
var Store = new DocumentStore { ConnectionStringName = "RavenDB" };
var instance = new EmbeddableDocumentStore { ConnectionStringName = "RavenDB" };
}
}
}
does not recognize EmbeddableDocumentStore. What is the namespace for EmbeddableDocumentStore?
After looking around in google groups and some experimenting, I got the solution
Use
Install-Package RavenDB.Embedded -Version 1.0.992
Also if its a console application: right click on the console project-->properties-->
Set Target framework to .NET Framework4 (as opposed to the default .NET Framework 4 Client Profile

Is it possible to Export a C++ CLI interface with MEF and Prism

I have a C++/CLI interface defined in a C++ library (Compiled with the /clr switch)
I also have a C# library.
My C# library defines:
- a class that implements Prism IModule interface.
- a class that implements the C++/CLI interface and is decorated with MEF Export attribute.
both the C# and the C++\CLI library are deployed into the same folder.
I am getting a ModuleLoadException from Prism saying that it can't find my C++/CLI assembly or one of its dependencies.
If I replace the C++/CLI assembly with a .NET one, everything works fine!
My question is then , is it at all possible to export a class that implements a C++\CLI interface with the export type being that interface?
Why do I have the interface defined in a C++/CLI library? I was hoping that a legacy C++ DLL we have could actually define their contracts in that C++\CLI libraries and have C# libraries reference that contract dll.
Maybe my approach is wrong, please let me know if you think there is a better way to achieve this.
I haven't really spent much time with C++/CLI before, but as it's a CLS-compliant language, it should just work. Here is an example
// CPPMEF_CPP.h
#pragma once
using namespace System;
using namespace System::ComponentModel::Composition;
namespace CPPMEF_CPP {
[InheritedExportAttribute]
public interface class ILogger
{
public:
virtual void Log(System::Object^ obj) = 0;
};
}
And in my C# console app:
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Text;
using CPPMEF_CPP;
namespace CPPMEF_CSharp
{
class Program
{
static void Main(string[] args)
{
var catalog = new AssemblyCatalog(typeof(Program).Assembly);
var container = new CompositionContainer(catalog);
var logger = container.GetExportedValue<ILogger>();
logger.Log("Test");
Console.ReadKey();
}
}
public class ConsoleLogger : ILogger
{
public void Log(object obj)
{
Console.WriteLine(obj);
}
}
}
There should be no special requirements for deploying C++/CLI assemblies, as it's all the same at deployment anyways. Can you check that any dependencies are deployed with your C++/CLI assembly too?