the1mason
the1mason
CC#
Created by the1mason on 4/20/2025 in #help
typeof(T).IsAssignableFrom does not work as I expected
11 replies
CC#
Created by the1mason on 4/20/2025 in #help
typeof(T).IsAssignableFrom does not work as I expected
The original prototype worked because I used a direct ProjectReference in both MVC and Plugin projects thus the .dll was the same and types did match fully
11 replies
CC#
Created by the1mason on 4/20/2025 in #help
typeof(T).IsAssignableFrom does not work as I expected
Also I have the solution to my problem 😎 The structure of my projects is the following: - PluginBase - NuGet package w/ the loader and IWebPlugin interface - Plugin1 - A test plugin - MVC - Web project MVC references PluginBase Plugin1 references PluginBase but even though they reference the same package with the same version, they reference their respective local copies, created on build action. It resulted in 2 absolutely identical IWebPlugin types loaded with the only difference being Module properties linking to different sources. The solution I have found after some thinking with @Left2Dotnet First, I have to exclude PluginBase from the build outptut, adding to the <PackageReference...>
<ExcludeAssets> runtime </ExcludeAssets>
<ExcludeAssets> runtime </ExcludeAssets>
Then I want to allow my Plugin1 to get and load the .dll of the PluginBase from MVC's dll folder. I did this by using .runtimeconfig.json I have created Plugin1.runtimeconfig.template.json in the Plugin1's project root and added the following:
{
"runtimeOptions": {
"additionalProbingPaths": [
"../."
]
}
}
{
"runtimeOptions": {
"additionalProbingPaths": [
"../."
]
}
}
It will try to look for .dll dependencies in the parent folder too (because plugins are located in /Plugins folder) And the problem is officially solved
11 replies
CC#
Created by the1mason on 4/20/2025 in #help
typeof(T).IsAssignableFrom does not work as I expected
I have an implementation that unloads assemblies but it does not prevent all memory leaks 'cause it's up to plugin's dev to ensure that when needed everything shuts down properly and there are no references to anything in the loaded context, so it can be collected by the GC when allowed
11 replies
CC#
Created by the1mason on 4/20/2025 in #help
typeof(T).IsAssignableFrom does not work as I expected
I have tried to debug it for a while and as far as I can tell, the problem is not really in this method. I have a prototype project that uses the same mechanism to resolve assemblies and create instances of IWebPlugin as in this case. It seems to me that I have messed up elsewhere but now it's too late and the debugger went nuts, so I'll try to solve it tomorrow and post an answer for history.
11 replies