3

I am currently trying to integrate an ASP.NET Core WebApi project into an WPF application (latest ASP.NET Core, latest .NET Framework). The idea is to provide a REST API for the user to control the application remotely. However, I was not able to integrate it into the WPF application and as soon as I reference the web project in the WPF project I am faced with a compilation error:

"Unknown build error, 'Cannot resolve dependency to assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.2.0, Culture=neutral PublicKeyToken=adb9793829ddae60' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event."

Any ideas how to solve that problem?

This is an example VS2017 solution that contains a WPF project and an ASP.NET Core project and I just added a reference to the ASP.NET Core project in the WPF project.

UPDATE: The ASP.NET Core project is set up to target the full .NET framework and is not using .NET Core.

2
  • ASP.NET Core can target either the .NET Core or the Full runtime. WPF only runs on the Full framework for now, so the ASP.NET Core project will have to target the Full framework as well Commented Sep 3, 2018 at 15:22
  • That's what I did in the project: ASP.NET Core targets the full runtime. This question is not about .NET Core but about ASP.NET Core running under the full .NET framework. Commented Sep 3, 2018 at 20:33

3 Answers 3

3

Just to solve your build errors, you can install required missing Nuget packages (dependencies of WebApplication1) and their dependencies.

I was able to successfully build and run your provided project by installing followinf Nuget packages on WpfApp1:

  1. Microsoft.AspNetCore.MVC.Core
  2. Microsoft.AspNetCore.Razor.Runtime
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, that is possible, however, that means I have to add a lot of NuGet packages to my startup project that are not necessary for it and "pollutes" the WPF project because it is not using anything of it. However it would be a workaround :-/.
@octoate but they are dependencies of WebApplication1, if you want to add reference to WebApplication1; you have to add references to its dependencies as well.
3

WPF doesn't yet support .NET Core. You cannot reference any .NET Core assemblies from a WPF application and consequently there is no way you can host an ASP.NET Core application in a WPF application.

Microsoft has announced .NET Core 3 support for Windows desktop applications (including WPF) from 2019: https://blogs.msdn.microsoft.com/dotnet/2018/05/07/net-core-3-and-support-for-windows-desktop-applications/

2 Comments

ASP.NET Core isn't tied to .NET Core. It can run on the Full Framework as well.
Like I already posted above: I know that and I am not using .NET Core but ASP.NET Core in combination with the full .NET framework. The wizard in VS2017 also allows to choose the full .NET framework and generates such a project.
1

I suggest you use plain WCF to accomplish this. WCF is also able to handle your calls RESTful. Just implement a service- and datacontract. To start the service in WPF, create a new 'ServiceHost' on startup to map it to a URL and port.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.