NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 25 26 27 28 29 … 93 Next »
pvrx2 / plugin assembly resolution

 
  • 0 Vote(s) - 0 Average
pvrx2 / plugin assembly resolution
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#1
2008-12-14, 08:37 AM
sub - did you have any further thoughts on pvrx2 resolving external assemblies used by plugins?

As a reminder - the dvbt radio plugin and service use some common classes etc. which are in the dvbtrlib class library. If I put dvbtrlib.dll only in the "plugins\DVB-T Radio" folder, pvrx2 can't find it because it goes looking for it in other plugins' folders or the plugins\Common folder and not in the "plugins\DVB-T Radio" folder.

The workaround is that it has to go in the "plugins\Common" folder but that doesn't seem right as there isn't anything in it that's common to any other plugin.

Cheers,
Brian
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#2
2008-12-14, 08:43 AM
You should be able to have in in common, or in the plugin folder...

But what you need to do is use it at plugin constructor time....as this is the only time that sub knows what directory the plugin lives in.

I use a static version method that loads the assembly and prints out the version number. This is enough to trigger subs assembly_resolve event.
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#3
2008-12-14, 09:23 AM
psycik Wrote:You should be able to have in in common, or in the plugin folder...
Yep I'd like to be in the plugin folder but not the common (that's part of my point).

Quote:But what you need to do is use it at plugin constructor time....
I don't want to use a plugin constructor as this will be run every time pvrx2 is started - it's an unnecessary overhead if someone isn't going to use my plugin every time they start pvrx2.

Quote:as this is the only time that sub knows what directory the plugin lives in.
Urmm - surely the fact it's loading the plugins means it knows where it's loading them from....???

My main point is that when the dvbt radio plugin is selected from the main menu, pvrx2 goes looking for the dvbrlib.dll but it has a broken search mechanism. This from an hour ago (it looks in the skinplugin folder and the common folder and repeats ad infinitum - it never attempts to look in the dvb radio folder)...
Quote:2008-12-14 08:20:33.613 VERBOSE [1] Looking for missing assembly in C:\Program Files\Devnz\GBPVR\plugins\SkinPlugin: DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null
2008-12-14 08:20:33.613 VERBOSE [1] Looking for missing assembly in plugin\common: DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null
2008-12-14 08:20:35.426 VERBOSE [1] Looking for missing assembly in C:\Program Files\Devnz\GBPVR\plugins\SkinPlugin: DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null
2008-12-14 08:20:35.426 VERBOSE [1] Looking for missing assembly in plugin\common: DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null
2008-12-14 08:20:35.551 ERROR [1] Unexpected error: System.IO.FileNotFoundException: Could not load file or assembly 'DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null'
at DvbRadio.DvbRadio.needsRendering()
at GBPVRX2.MenuTask.x0be92cb4e3ac1817.needsRendering()
at GBPVRX2.MenuTask.x9006c1ed9ccb79de.needsRendering()
at GBPVRX2.x0061b801bdf12d35.xdb012c437aec4a40(Boolean xd23bf32f3b17e3be)
at GBPVRX2.xb979ad394703258e.xfb409e85bd292293(String[] xf18a926310372520)

2008-12-14 08:20:35.551 VERBOSE [1] Looking for missing assembly in C:\Program Files\Devnz\GBPVR\plugins\SkinPlugin: DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null
2008-12-14 08:20:35.551 VERBOSE [1] Looking for missing assembly in plugin\common: DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null
2008-12-14 08:20:35.660 ERROR [1] Unexpected error: System.IO.FileNotFoundException: Could not load file or assembly 'DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'DvbrLib, Version=1.5.3251.36171, Culture=neutral, PublicKeyToken=null'
at DvbRadio.DvbRadio.needsRendering()
at GBPVRX2.MenuTask.x0be92cb4e3ac1817.needsRendering()
at GBPVRX2.MenuTask.x9006c1ed9ccb79de.needsRendering()
at GBPVRX2.x0061b801bdf12d35.xdb012c437aec4a40(Boolean xd23bf32f3b17e3be)
at GBPVRX2.xb979ad394703258e.xfb409e85bd292293(String[] xf18a926310372520)
JavaWiz
Offline

Posting Freak

Jacksonville, FL. USA
Posts: 2,522
Threads: 141
Joined: Dec 2006
#4
2008-12-14, 10:08 AM
You might take a look at this code and modify as needed.

Plugin constructor code:

Code:
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]AppDomain[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] currentDomain = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]AppDomain[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].CurrentDomain;[/SIZE]
[SIZE=2]currentDomain.AssemblyResolve += [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]ResolveEventHandler[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Core[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].ResolveAssemblyEventHandler);[/SIZE]

A static method in my Core class:

Code:
public static Assembly ResolveAssemblyEventHandler(object sender, ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
Assembly MyAssembly, objExecutingAssemblies;
objExecutingAssemblies = Assembly.GetExecutingAssembly();
AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();
RegistryKey localMachine = Registry.LocalMachine;
string name = @"SOFTWARE\devnz";
RegistryKey regKey = localMachine.OpenSubKey(name);
string key = "GBPVR InstallDir";
string gbpvrInstallDir = (string)regKey.GetValue(key.ToUpper());
string dllFileWithoutExtention = args.Name.Substring(0, args.Name.IndexOf(","));
string missingDllName = dllFileWithoutExtention + ".dll";
// Default to gbpvr install directory
string strTempAssmbPath = gbpvrInstallDir + missingDllName;
//Build the path of the assembly from where it has to be loaded.
if (File.Exists(gbpvrInstallDir + @"Plugins\common\" + missingDllName))
{
  strTempAssmbPath = gbpvrInstallDir + @"Plugins\common\" + missingDllName;
}
else if (File.Exists(gbpvrInstallDir + missingDllName))
{
  strTempAssmbPath = gbpvrInstallDir + missingDllName;
}
else
  MessageBox.Show("Unable to locate DLL: " + missingDllName, "Missing DLL");

//Load the assembly from the specified path.
MyAssembly = Assembly.LoadFrom(strTempAssmbPath);
//Return the loaded assembly.
return MyAssembly;
}

You'll probably have to modify to include the directory your plugin DLL is running from. I believe you can get that off the objExecutingAssemblies somehow.
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#5
2008-12-14, 10:43 AM
Thanks JavaWiz - you actually posted something like this last time I brought the subject up and I have a variation of the ResolveAssemblyEventHandler() embedded in my dvb radio service as a result....and it works very nicely.

However, the plugin is a separate beast to the service and my question still comes down to why pvrx2 can quite happily resolve my dvbtlib.dll if I put it in plugins\common BUT when it's not there, it goes into an infinite loop searching plugins\SkinPlugin and plugins\common.....

...or plugins\A-N-Other-Plugin and plugins\common. The log extract I included above isn't from a dvb radio log it's from pvrx2.exe.log. The issue is that it will (seemingly) randomly pick another plugin's folder to search but doesn't try the folder where the actual plugin is.
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#6
2008-12-14, 07:15 PM
sub also uses that code that javawiz posted.

My Idea was just a static version method, so you're not consuming any resources etc. It just forces the link between the various assemblies. It's basically a one liner that you can add to get the external references going.

So add this to the external dll

Code:
public static string Version
{
    get
    {
         System.Reflection.Assembly myAsm = System.Reflection.Assembly.GetExecutingAssembly();
         return myAsm.GetName().Version.ToString(3);
    }
}

And just call that from your plugin code at constructor time... I spent a bit of time fussing with this, as for ML3 I have the plugin dll, then a common dll, then a track reading dll - so 3 levels, and this was the best and simplest way I could get it working.. I'd tried all the assembly resolves but it would never get the 3rd dll.
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#7
2009-02-05, 11:14 PM
Thanks - I've only just got around to looking at this. I've done a variation on it and it seems to work fine.

BTW as the Assembly class is static, it's possible to trim it down a bit (not that it matters much)...
Code:
public static string Version
{
    get { return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
}
Cheers,
Brian
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  PIP plugin for Kodi sgilani 2 2,831 2022-10-17, 12:44 AM
Last Post: sgilani
  New Systems Plugin kirschey 10 3,353 2020-11-14, 08:01 PM
Last Post: sub
  VIdeo playback from plugin mvallevand 5 3,463 2015-08-06, 10:43 PM
Last Post: sub
  Attention Sub: Open TV / Custom Data Grabber plugin Benoire 2 2,907 2014-11-14, 02:05 AM
Last Post: Benoire
  Is the input file for pvrx2.exe -import unique to NextPVR? spinnaker 1 1,767 2013-10-08, 02:25 AM
Last Post: sub
  API docs to help with plugin development? McBainUK 3 2,772 2013-06-08, 06:14 PM
Last Post: sub
  Refreshing TV Guide Data (after System plugin EPG update) imilne 13 6,100 2013-03-24, 08:03 PM
Last Post: imilne
  sabnzbd plugin to show processed files Wakalaka 1 1,951 2013-03-12, 06:48 AM
Last Post: psycik
  Plugin problems with started from the command line mvallevand 11 4,997 2012-08-12, 07:56 PM
Last Post: sub
  Dll assembly referencing mvallevand 5 2,199 2012-03-05, 04:07 AM
Last Post: mvallevand

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode