简体   繁体   English

安装后Visual Studio VSPackage行为不同

[英]Visual studio VSPackage behavior different after installation

I have developped a Visual studio 2010 VSPackage in C#. 我已经用C#开发了Visual Studio 2010 VSPackage。 It's role is to show an assembly types and methods in a Treeview. 它的作用是在Treeview中显示程序集类型和方法。 It uses reflexion like this : 它使用像这样的反射:

Assembly assembly = Assembly.LoadFile(strAssemblyPath);  
foreach (Type a_type in assembly.GetTypes())  
{  
    foreach (MethodInfo mi in a_type.GetMethods())  
    {  
        //code to handle methods here  
    }  
}  

I have several Assemblies that reference others, all situated in the same folder. 我有几个引用其他组件的程序集,它们都位于同一文件夹中。

It works fine when I debug the application : the getTypes() and getMethods() don't raise any errors when trying to load types from others assemblies. 当我调试应用程序时,它运行良好:尝试从其他程序集中加载类型时,getTypes()和getMethods()不会引发任何错误。

When I generate a .vsix installer, (debug or release), and use the plugin afer installing it, the getTypes() and GetMethods() raise errors of type : 'Could not load file or assembly or one of its dependencies' but the assemblies are in the folder... 当我生成.vsix安装程序(调试或发行版)并在安装后使用插件时,getTypes()和GetMethods()会引发以下类型的错误:“无法加载文件或程序集或其依赖项之一”,但程序集在文件夹中...

Some more informations : 更多信息:

  • I use the default settings for my VSPackage solution. 我对VSPackage解决方案使用默认设置。
  • the command line in debug is "C:\\Program Files (x86)\\Visual Studio 2010 Ultimate\\Common7\\IDE\\devenv.exe /rootsuffix Exp" 调试中的命令行为“ C:\\ Program Files(x86)\\ Visual Studio 2010 Ultimate \\ Common7 \\ IDE \\ devenv.exe / rootsuffix Exp”
  • I try the same action on the exact same assemblies in the exact same folder while debugging and after installation of the package. 在调试和安装软件包后,我对完全相同的文件夹中的完全相同的程序集尝试相同的操作。
  • Visual studio is started as Administrator in both cases 在两种情况下,Visual Studio均以管理员身份启动

Does anyone know why the behavior of the GetTypes() and GetMethods() is different ? 有谁知道为什么GetTypes()和GetMethods()的行为不同?

Well, I still don't know why the behavior is different, but I was able to limit the impact of the error with correct error handling. 好吧,我仍然不知道为什么行为会有所不同,但是我能够通过正确的错误处理来限制错误的影响。 The error handling I use is this ; 我使用的错误处理是这样;

Type[] types = null;
try
{
    types = assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
    types = e.Types;
    StringBuilder strErrors = new StringBuilder();
    foreach (Exception exError in e.LoaderExceptions)
    {
        //Message errors can appear several times.
        if (!strErrors.ToString().Contains(exError.Message))
        {
             strErrors.Append(exError.Message);
             Exception innerError = exError.InnerException;
             while (innerError != null)
             {
                 strErrors.Append(innerError.Message);
                 innerError = innerError.InnerException;
             }
        }
    }
    //trace the error
}
if (types != null)
{
    foreach (Type a_type in types)
    {
         //handle types in here
    }
}

Before, I just catched the exception and didn't handle the types defined in the ReflectionTypeLoadException.Types. 以前,我只是捕获了异常,并且没有处理ReflectionTypeLoadException.Types中定义的类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从VSPackage获取当前运行的Visual Studio安装路径 - How get the current running Visual Studio installation path from VSPackage 从VSPackage获取Visual Studio配色方案 - Get the Visual Studio color scheme from a VSPackage 如何在VSPackage插件中捕获Visual Studio命令? - How to capture Visual Studio commands in a VSPackage Plugin? 如何使用vspackage从Visual Studio中的不同扩展名合并两个名称相同的顶级菜单 - How to merge two top level menu with same name from different extension in visual studio using vspackage Visual Studio扩展(VSPackage)在所有实验实例中运行,但在作为.vsix安装后不运行,VS2010除外 - Visual Studio Extension (VSPackage) runs in all Experimental Instances, but does not run after being installed as a .vsix, except in VS2010 Visual Studio Shell 14 升级破坏了 VSPackage 中的命令捕获 - Visual Studio Shell 14 upgrade ruins command capturing in VSPackage 如何更改Visual Studio集成包(VSPackage)上的图标? - How do I change icon on a Visual Studio Integration Package (VSPackage)? 如何使用VSPackage检测Visual Studio IDE是否正在关闭? - How to Detect if Visual Studio IDE is closing using VSPackage? 动态显示工具栏上的自定义Visual Studio VSPackage命令 - Dynamic display custom Visual Studio VSPackage command on toolbar 如何在VSPackage中动态添加命令(Visual Studio 2013程序包) - How to add commands dynamically in VSPackage (Visual Studio 2013 Package)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM