Reputation: 1107
We have a huge collection of classic .Net libraries written in anything from .Net 3.5 to 4.6. This includes our core business logic and data model classes we use across various .Net solutions using WCF, Web API, Asp.Net, WPF and Windows Forms. It is only natural therefore that when looking into creating a UWP app, we'd need to reuse some of these .Net dlls.
I've create a portable class library (PCL) in which I reference one of our .Net 4.5 dlls. I then created a class in the PCL that implements one of the 4.5 classes:
using DODServiceLib.Models;
namespace PortableClassLibrary
{
public class UtilityStats : ProcessorStats
{
}
}
ProcessorStats is from the 4.5 dll, DODServiceLib.Models.
In my UWP app, I've added a project reference to the PCL, PortableClassLibrary and added a using statement in my code behind, this is where I need to use the implementation of my .Net class:
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.Net.Http;
using System.Threading.Tasks;
using PortableClassLibrary;
namespace HelloWorld
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
var utilityStats = new UtilityStats();
}
}
}
When building the solution, I get these errors against the UWP HelloWorld app:
Type universe cannot resolve assembly: DODServiceLib, Version=20.17.7.28, Culture=neutral, PublicKeyToken=null.
Cannot resolve Assembly or Windows Metadata file 'DODServiceLib.dll'
Why is the UWP app looking for a reference to the .Net DLL (DODServiceLib) when it only uses the PCL?
Can I not use a PCL like this as a "wrapper" for a classic .Net library?
Upvotes: 1
Views: 384
Reputation: 302
Why is the UWP app looking for a reference to the .Net DLL (DODServiceLib) when it only uses the PCL?
It's normal. Your PCL add added reference to that .NET DLL, so it certainly will look for this dll. But this dll is not support in UWP. That's reason why you will get the exception. UWP project can reference Universal Windows Class Library, Portable Library or Windows Runtime Component.It doesn't mean that you could use PCL to wrap the classic .NET library.That's entirely different thing. I think what you need to do is copy all the code from your .NET library into PCL and then start to eliminate/replace all code which doesn't fit.
Upvotes: 1