[英]Error when calling a .net dll from Com Visible dll using javascript
I am developing a windows 7 gadget.I am creating an activex object and loading the assembly.I am following the methodlogy mentioned here at codeproject (GadgetInterop). 我正在开发Windows 7小工具,正在创建Activex对象并加载程序集。我正在遵循代码项目 (GadgetInterop)此处提到的方法。 One of the tasks of the gadget is to interface with Facebook.
该小工具的任务之一是与Facebook交互。
This is how I am referencing: Javascript creates a GadgetBuilder object. 这就是我的引用方式:Javascript创建了一个GadgetBuilder对象。 From here I load the my library.
从这里加载我的库。 say "MyLibrary.dll".
说“ MyLibrary.dll”。
If I test my code from a ASP.NET form it works perfectly. 如果我从ASP.NET表单测试我的代码,则可以完美运行。 However, When I run it from my html page by trying to load it using javascript, I get the following error:
但是,当我尝试通过使用javascript从html页面运行它时,出现以下错误:
Could not load file or assembly 'facebook, Version=2.1.3654.38113, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
无法加载文件或程序集'facebook,Version = 2.1.3654.38113,Culture = neutral,PublicKeyToken = null'或其依赖项之一。 The system cannot find the file specified.
该系统找不到指定的文件。
I verified that the dll's are in the same folder as "MyLibrary.dll". 我确认dll与“ MyLibrary.dll”位于同一文件夹中。
You're not forced to use a reflection-based assembly loader for .net code in desktop gadgets, you can write the assembly to be com visible, using class ids, etc. This article provides an example of using .net to achieve what you're trying to do without the "adapter". 您无需在桌面小工具中为.net代码使用基于反射的程序集加载器,您可以使用类ID等将程序集编写为com可见。 本文提供了一个使用.net来实现目标的示例正在尝试没有“适配器”的情况。
That being said, there are various problems with activex based desktop gadgets that you should be aware of: 话虽这么说,基于Activex的桌面小工具存在各种问题,您应该注意:
So really although you can do it without reflection, using reflection can be a better option because you can copy the adapter assembly to an alternative folder, use it to load the current assembly and then unload it when the gadget is closed or finished using it. 因此,实际上,尽管您可以在不进行反射的情况下进行操作,但是使用反射可能是更好的选择,因为您可以将适配器程序集复制到备用文件夹,使用它加载当前程序集,然后在小工具关闭或使用完该组件时将其卸载。 This eliminates the first issue of not being able to uninstall the gadget because the hosting assembly is located in a different folder and the reflected assembly is unloaded when the gadget is closed anyway.
这消除了第一个无法卸载小工具的问题,因为托管程序集位于另一个文件夹中,并且无论如何关闭小工具时,都会卸载反射的程序集。
The reason facebook.dll isn't loading is because the loader you're using doesn't correctly resolve dependencies (it can't find the file because it doesn't know where to look). facebook.dll之所以无法加载,是因为您使用的加载器无法正确解析依赖项(由于找不到位置,因此无法找到文件)。 You're welcome to try our reflection-based assembly loader called PluginLoader and see if that works.
欢迎您尝试我们称为PluginLoader的基于反射的程序集加载器,看看是否可行。 We haven't had an official release for it yet but we were intending to make it widely available and recommended for use by all developers to try and eliminate the problems with ActiveX and Windows Desktop Gadgets.
我们尚未发布它的正式版本,但我们打算使其广泛可用,并建议所有开发人员使用它来尝试消除ActiveX和Windows桌面小工具的问题。 Because we haven't officially released it you'll have to install our gadget, Auction Sidebar Tool which will install the plugin loader ready for use with the following code:
由于我们尚未正式发布它,因此您必须安装我们的小工具“ 拍卖侧边栏工具” ,该工具将安装插件加载程序,以供以下代码使用:
var plLoader = new ActiveXObject("Sidebar.PluginLoader");
var myLibrary = plLoader.LoadAssembly(classToLoad,
System.Gadget.path+"\\path\\to\\MyLibrary.dll");
myLibrary.GetFaceBookFeeds();
Where class to load is the class you need to load in the format Namespace.Class (ie MyLibrary.MyClass ). 要加载的类是需要以Namespace.Class格式(即MyLibrary.MyClass )加载的类。 We specifically coded it to correctly resolve any dependencies so it should work for you just fine.
我们专门对其进行了编码,以正确解决任何依赖关系,因此它应该可以为您正常工作。 If it does work for you, you're welcome to include it with your gadget.
如果它对您有用,则欢迎将其包含在小工具中。 All you need is the PluginLoader.js and PluginLoader.dll files from the AuctionSidebarTool folder, but you'll need to edit the PluginLoader.js file to remove the parts that reference our assembly (line 110 onwards).
您需要做的只是AuctionSidebarTool文件夹中的PluginLoader.js和PluginLoader.dll文件,但是您需要编辑PluginLoader.js文件以删除引用我们装配体的零件(从第110行开始)。 If you include this in your project, it will check for an existing PluginLoader.dll and if it fails, it will copy it to the Windows Sidebar folder in local AppData, register it and provide the
AddInLoader
object with the methods LoadAssembly
and UnloadAssembly
. 如果将其包含在项目中,它将检查是否存在现有的PluginLoader.dll,如果失败,则将其复制到本地AppData中的Windows Sidebar文件夹中,进行注册并为
AddInLoader
对象提供LoadAssembly
和UnloadAssembly
方法。 If you need any extra help just let me know in the comments. 如果您需要其他帮助,请在评论中告诉我。
Hope that helps. 希望能有所帮助。 That's probably the longest answer I've written so far on SO :)
到目前为止,这可能是我写的最长的答案:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.