哪里的Visual Studio查找组件? [英] Where does Visual Studio look for assemblies?

查看:216
本文介绍了哪里的Visual Studio查找组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有了一个框架,它包含可以派生开发许多应用程序许多基类。在这些类之中有System.Windows.Forms.Panel的一个子类的,我写了自己的设计师。一切正常与Visual Studio 2005,但不顺心的事时,我尝试移动到VS2010。这是我做的一个大大简化版本:

I've got a framework which consists of many base classes that can be derived to develop many apps. Among these classes there is a subclass of System.Windows.Forms.Panel for which I wrote its own designer. Everything is working fine with Visual Studio 2005, but something goes wrong when I try to move to VS2010. This is a much simplified version of what I am doing:

我有一个名为CoreClasse项目,其中包含一个接口和两个类:

I have a project called CoreClasse which contains an interface and two classes:

public interface IConf
{
    string foo { get; set; }
    void InitFoo();
}

public class SimpleClass
{
    public string foo;
}

public class ConfLoader
{
    public static IConf LoadConf()
    {
        AssemblyName anAssemblyName = new AssemblyName("ConfClasses");
        Assembly anAssembly = Assembly.Load(anAssemblyName);
        IConf result = (IConf)anAssembly.CreateInstance("ConfClasses.ConfClass");
        result.InitFoo();
        return result;
    }
}



然后有一个项目ConfClasses它引用CoreClasses并含有只是一个类实现IConf:

Then there is a project ConfClasses which references CoreClasses and contains just one class implementing IConf:

public class ConfClass : IConf
{
    public SimpleClass confVal;

    public string foo
    {
        get { return confVal.foo; }
        set { confVal.foo = value; }
    }

    public void InitFoo()
    {
        confVal = new SimpleClass();
        confVal.foo = "bar";
    }
}



终于有用于控制其引用的一个项目只有CoreClasses并包含面板的子类和相关设计师:

And finally there is a project for the controls which references only CoreClasses and contains a subclass of Panel and the associated designer:

[Designer("MyControls.Design.SimplePanelDesigner", typeof(IRootDesigner))]
public class SimplePanel : Panel
{
    public SimpleClass dummy = new SimpleClass();
}

public class SimplePanelDesigner : DocumentDesigner
{
    public IConf DesignerConf;

    public SimplePanelDesigner()
        : base()
    {
        DesignerConf = ConfLoader.LoadConf();
    }
}

现在我创造另一种解决方案,它引用所有这些DLL和包含SimplePanel一个空的子类。当我双击这个类SolutionExplorer SimplePanelDesigner的构造函数被执行,ConfLoader的方法LoadConf被调用。这意味着它们ConfClasses.dll被dinamically加载并创建ConfClass的一个实例。一切都很好了这一刻,但是当InitFoo被调用时引发此异常:

Now I create another solution which references all these dlls and contains an empty subclass of SimplePanel. When I double click on this class in SolutionExplorer the constructor of SimplePanelDesigner is executed and the method LoadConf of ConfLoader is called. This means that ConfClasses.dll is loaded dinamically and an instance of ConfClass is created. Everything is fine up to this moment, but when InitFoo is called this exception is raised:

无法加载文件或程序集CoreClasses,版本= 1.0.0.0文化=中性公钥= null或它的一个依赖。该系统找不到指定的文件。

为了使事情变得更难,异常实际上并不raisedin这个例子,但这正是那种istructions我真正的应用程序正在执行,异常我得到。我没有这里发生了什么的线索。 VS是执行其在CoreClasses的方法。为什么试图再次加载呢?而它在哪儿找呢?我检查了当前的AppDomain,太多,但它有CoreClasses其加载的组件之一,它似乎并没有改变。

To make things harder, the exception is not actually raisedin this example, but this is exactly the kind of istructions my real app is executing, and the exception I am getting. I haven't got a clue of what's happening here. VS is executing a method which IS in CoreClasses. Why is it trying to load it again? And where is it looking for it? I checked the current AppDomain, too, but it has CoreClasses among its loaded assemblies, and it does not seem to change.

我想补充一些更多的细节,每一个项目建立在一个共同的文件夹(而不是项目文件夹内通常的OBJ / Debug文件夹中),并有我的电脑此刻的dll文件,没有其他副本,我开始我的测试。然后,所有被引用的DLL的一个副本了一系列在我USERPROFILE的AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies文件夹中的文件夹就完成了,这似乎是VS正在寻找的地方的组件时的Assembly.Load被执行,我能找到CoreClasses副本那里。我试图清理所有文件夹,重建的一切,并随时向不同的解决方案打开/在每个组合关闭,但没有任何起色。

Just to add some more details, every project is build in a common folder (not the usual obj/debug folder inside the project folder), and there is no other copy of my dlls on the PC at the moment I start my test. Then a copy of all the referenced dlls is done in a series of folders in the AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies folder of my userprofile, and this seems to be the place VS is looking for the assemblies when Assembly.Load is executed, and I can find a copy of CoreClasses there. I tried to clean all the folders, to rebuild everything, and to keep the different solutions opened/closed in every combination, but without any improvement.

编辑:

正如GranMasterFlush建议,这是由异常产生的FusionLog:

As GranMasterFlush suggested, this is the FusionLog generated by the exception:

=== Pre-bind state information ===
LOG: User = FCDB\fc0107
LOG: DisplayName = XEngine.Core, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).



编辑2

EDIT 2

我想补充一些信息,我看了看我的简单的例子产生的融合日志和发现,尝试加载CoreClasses,但好歹VisualStudio中找到一个方法来应付它一模一样的日志已经生成。

Just to add some info, I took a look at the fusion logs generated by my simple example and found out that exactly the same log has been generated while trying to load CoreClasses, but someway VisualStudio finds a way to cope with it.

推荐答案

我刚刚找到了发生了什么。在简单的例子,真实的东西之间的区别是,有涉及一个外接程序的事实。
这是一个相当日志故事,但是这是它。


你可以从代码示例中看到的,我加载通过反射的ConfClasses DLL,以避免添加一个引用它。这是在运行时正常,但设计人员报怨说,它不能够施展IConf到IConf。这是因为CoreClasses.dll从AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies装设计师开始的时候,却ConfClasses.dll从我的bin文件夹中加载等等都是它的引用,所以有两个CoreClasses.dll的版本,不同的版本IConf的。


要绕过我开发的外接程序,当一个组件装入在设计时的Assembly.Load,增加了该组件的引用,该问题,然后清洗引用当最后设计师窗口关闭。


一切都与VS2005 OK,但使用ProcMon.exe我发现VS2010添加了一个新的文件夹所在的加载项查找组件:程序文件(x86)\Microsoft Visual Studio中10.0\Common7\IDE\CommonExtensions\DataDesign


我有我的复制组装和一切再次工作。现在只要找到一种方法,有人工添加的东西的问题。

I've just found out what's happening. The difference between the simple example and the real thing is the fact that there is an AddIn involved. It's quite a log story, but this is it.
As you can see from the code sample, I load the ConfClasses dll via reflection in order to avoid to add a reference to it. This is fine at runtime, but the designer complains saying that it's not able to cast IConf to IConf. This happens because CoreClasses.dll is loaded from AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies when the designer starts, but ConfClasses.dll is loaded from my bin folder and so are its references, so there are two versions of CoreClasses.dll and different versions of IConf.
To bypass the problem I developed an AddIn that, when an assembly is loaded with Assembly.Load at design time, adds a reference to that assembly, and then cleans the references when the last designer window is closed.
Everything was OK with VS2005, but using ProcMon.exe I found out that VS2010 added a new folder where the addins look for assemblies: Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\CommonExtensions\DataDesign
I copied my assembly there and everything works again. Now it's only a matter of finding a way to add things there manually.

这篇关于哪里的Visual Studio查找组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆