C
C#_read_only_

MEF No exports were found that match the constraint

Hi, i'm trying to implement MEF in my WPF app, however i'm getting this error, not sure why anymore. Everything looks correct for me This is my plugin:
public interface IPlugin
{
void Process();
string Name { get; }
string Description { get; }
}

[Export(typeof(IPlugin))]
public class Plugin : IPlugin
{
public string Name => "Plugin";
public string Description => "Plugin";

public void Process()
{
Console.WriteLine("Plugin");
}
}
public interface IPlugin
{
void Process();
string Name { get; }
string Description { get; }
}

[Export(typeof(IPlugin))]
public class Plugin : IPlugin
{
public string Name => "Plugin";
public string Description => "Plugin";

public void Process()
{
Console.WriteLine("Plugin");
}
}
and this is part of my WPF App.xaml.cs
public interface IPlugin
{
void Process();
string Name { get; }
string Description { get; }
}

public partial class App : Application
{
[Import(typeof(IPlugin))]
public IPlugin plugin;

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

string plugins = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"WPFAPP", "plugins");

if (!Directory.Exists(plugins))
{
Directory.CreateDirectory(plugins);
}

var catalog = new DirectoryCatalog(plugins);

try
{
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
catch (Exception ex)
{
Console.WriteLine($"ex: {ex}");
}
}
}
public interface IPlugin
{
void Process();
string Name { get; }
string Description { get; }
}

public partial class App : Application
{
[Import(typeof(IPlugin))]
public IPlugin plugin;

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

string plugins = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"WPFAPP", "plugins");

if (!Directory.Exists(plugins))
{
Directory.CreateDirectory(plugins);
}

var catalog = new DirectoryCatalog(plugins);

try
{
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
catch (Exception ex)
{
Console.WriteLine($"ex: {ex}");
}
}
}
is there something wrong?
C
canton717d ago
Note that your two IPlugin interfaces are different types So the one which your plugin claims that it implements is a different interface to the one which your WPF app is trying to find implementations of
R
_read_only_17d ago
looks like its the same when I leave IPlugin interface in wpf app, and add project reference to plugin to use same interface
C
canton717d ago
So your plugin references your WPF app, but your WPF app is trying to load the plugin? That's a circular dependency Normally you need to have another assembly, which contains the common types that both your app and your plugin rely on
R
_read_only_17d ago
just as a quick test, also tried with creating another shared dll this is what I have currently
namespace Wpf.Shared
{
public interface IPlugin
{
void Process();
string Name { get; }
string Description { get; }
}
}
namespace Wpf.Shared
{
public interface IPlugin
{
void Process();
string Name { get; }
string Description { get; }
}
}
namespace Wpf.Private;

[Export(typeof(IPlugin))]
public class Plugin : IPlugin
{
public string Name => "Plugin";
public string Description => "Plugin";

public void Process()
{
Console.WriteLine("Plugin");
}
}
namespace Wpf.Private;

[Export(typeof(IPlugin))]
public class Plugin : IPlugin
{
public string Name => "Plugin";
public string Description => "Plugin";

public void Process()
{
Console.WriteLine("Plugin");
}
}
public partial class App : Application
{
[Import(typeof(IPlugin))]
public IPlugin plugin;

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

string plugins = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"WPFAPP", "plugins");

if (!Directory.Exists(plugins))
{
Directory.CreateDirectory(plugins);
}

var catalog = new DirectoryCatalog(plugins);

try
{
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
catch (Exception ex)
{
Console.WriteLine($"ex: {ex}");
}
}
}
public partial class App : Application
{
[Import(typeof(IPlugin))]
public IPlugin plugin;

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

string plugins = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"WPFAPP", "plugins");

if (!Directory.Exists(plugins))
{
Directory.CreateDirectory(plugins);
}

var catalog = new DirectoryCatalog(plugins);

try
{
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
catch (Exception ex)
{
Console.WriteLine($"ex: {ex}");
}
}
}
both reference .Shared hi @Lex Li you recommended me MEF yesterday, do you have any idea whats wrong here
LL
Lex Li17d ago
I will stick to working samples like https://github.com/bezzad/MEF-Sample instead of rolling out my own.
GitHub
GitHub - bezzad/MEF-Sample: Sample of Managed Extensibility Framewo...
Sample of Managed Extensibility Framework (MEF). Contribute to bezzad/MEF-Sample development by creating an account on GitHub.
R
_read_only_17d ago
chatgpt for the win lol, idk how this happened but its working now
However, I noticed that the Plugin class is using the [Export] attribute from the System.Composition namespace, while the App class is using the [Import] attribute from the System.ComponentModel.Composition namespace. These are two different versions of MEF and they're not compatible with each other.
However, I noticed that the Plugin class is using the [Export] attribute from the System.Composition namespace, while the App class is using the [Import] attribute from the System.ComponentModel.Composition namespace. These are two different versions of MEF and they're not compatible with each other.
Want results from more Discord servers?
Add your server
More Posts
✅ WPF - set UIElement (image) in XAML depending on databound Property Enum valueI am trying to dynamically change a StatusBar image via a view's XAML depending upon a databound VieASP.NET Controller API + Blazor Client UI resources and helpHello! I'm doing a side project where I created the backend API with simple CRUD functionality and A✅ Run PuppeteerSharp in Docker ContainerI have an endpoint that creates PDFs using PuppeteerSharp. I work fine locally because it can automaDocker + Blazor + MSSQL handshake errorWhen I run dotnet ef database update I get the following error : ``Microsoft.Data.SqlClient.SqlExceProblem with corner radius XAML propertyI use a border with these properties: ```<Border CornerRadius="3" Background="{StaticResource Edito✅ :white_check_mark: Dictionary<int, ...> lookup time seems a bit too slowI was profiling a program, and I saw this: ```cs 100 % HasObject • 136 ms • 189 217 Calls • Engine.Rhow to read .txt file next to the Program.csi have the following code that is begin run ```cs string fileContent = File.ReadAllText("hamlet.txt✅ Linker Error Trying to Build OpenSSL Static LinkingHello, I've been trying to compile and build OpenSSL to try and encrypt a text file using AES 256 buHow things get to the placeI have found this one thing by Microsoft that confused me so much ```cs public async Task<IActionResVisual code studio and msbuildim currently having problems while scripting apparently when i press (Run Build Task) im getting thiMediatR - System.Text.Json.JsonException: 'S' is an invalid start of a value.I have a project with Clean Architecture and MediatR. My API gets the request fine and the command Blazor, auto unsubscribe patternI have created website using blazor, and if some component subscribe to something then it implement ✅ Form1.resx file gives error on Internet or Restricted zoneForm1.resx file gives error on Internet or Restricted zone I can't fix it error (english):Severity LHelp with API structureI want to create modular API structure https://timdeschryver.dev/blog/maybe-its-time-to-rethink-our-✅ WPF - how to correctly call a method in the ViewModel when an event occurs in the View?I want to call a method in the ViewModel when an event happens in the View. That is, when the View Blazor help needed. How can i Validate datalist entries in a child componentI have written a Blazor testapp that has an EditForm with a child component in the parent component.Inlcude content after run a command (.csproj)Hey i wanna ask if it would possible to place this after the cmake building command? ```cs <IteOpinion on the code i've writtenHello, I have a discord bot im working on, the code i am about to show reads a JSON Config file. I w✅ Receiving Input While Minimized (WinForms C#)Pretty general question here. How would I go about receiving input from my user while they aren't tSlack app - Trigger ID expiredHi, so I'm testing out a Slack app from here https://github.com/soxtoby/SlackNet/blob/master/Example