如何强制加载组件?

时间:2014-04-03 10:04:22

标签: c# .net .net-assembly resourcedictionary

我尝试使用外部程序集中的资源:

<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/<name>;component/Images/Flags.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

问题是,我经常得到XamlParseException告诉它,它无法加载程序集(尽管如此,请求程序集在同一文件夹中与提问程序一样)。当然,References部分正确提到了请求的程序集。

我做了一个黑客;在请求的程序集中创建了一个虚拟类,并在该控件的InitializeComponent()之前实例化它 - 从而强制加载该程序集,然后一切正常。

但是如何以正确的方式强制加载装配?我确信这个问题有某种理智的解决方案......

或者:为什么WPF在加载程序集时遇到问题,该程序集被正确引用并与调用程序集放在同一个文件夹中?


我已经检查过,Visual Studio会尝试在以下文件夹中找到请求的程序集:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\<name>  
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\<name>\<name>   
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\<name> 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\<name>\<name>  
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\<name>\<name> 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TemplateProviders\<name> 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TemplateProviders\<name>\<name>  
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Platform\Debugger\<name>   
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Platform\Debugger\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\DataCollectors\<name> 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\DataCollectors\<name>\<name>  
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\DataCollectors\x86\<name> 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\DataCollectors\x86\<name>\<name>  
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SharePoint\Extensions\BCS\<name>   
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\SHAREPOINT\EXTENSIONS\BCS\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Performance Tools\Plugins\<name> 
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\TEAM TOOLS\PERFORMANCE TOOLS\PLUGINS\<name>\<name>  
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLDB\<name>   
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\SQLDB\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLEditor\<name>   
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\SQLEDITOR\<name>\<name>    
C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\<name>  
C:\PROGRAM FILES (X86)\MICROSOFT SQL SERVER\110\DAC\BIN\<name>\<name>   
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\<name>   
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\WEB TOOLS\PUBLISH\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\Project\<name>   
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\PROJECT\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\ReferenceManager\<name>  
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\REFERENCEMANAGER\<name>\<name>   
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TailoredProjectServices\<name>   
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TAILOREDPROJECTSERVICES\<name>\<name>    
C:\Program Files (x86)\Common Files\Microsoft Shared\SQL Server Developer Tools\<name>  
C:\PROGRAM FILES (X86)\COMMON FILES\MICROSOFT SHARED\SQL SERVER DEVELOPER TOOLS\<name>\<name>   
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\cgiahkbv.mbu\<name>  
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\CGIAHKBV.MBU\<name>\<name>   
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v4.0\<name>   
C:\PROGRAM FILES (X86)\MSBUILD\MICROSOFT\VISUALSTUDIO\LIGHTSWITCH\V4.0\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLDB\Designers\<name> 
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\SQLDB\DESIGNERS\<name>\<name>  
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\<name>  
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TEAMFOUNDATION\TEAM EXPLORER\<name>\<name>   
C:\Program Files (x86)\Common Files\Microsoft Shared\SQL Debugging\<name>   
C:\PROGRAM FILES (X86)\COMMON FILES\MICROSOFT SHARED\SQL DEBUGGING\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\VsGraphics\<name>  
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\VSGRAPHICS\<name>\<name>   
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLEditor\<name>   
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\SQLEDITOR\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\ConnectedServices\<name> 
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CONNECTEDSERVICES\<name>\<name>  
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SharePoint\Extensions\ListDesigner\<name>  
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\SHAREPOINT\EXTENSIONS\LISTDESIGNER\<name>\<name>   
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\Web\Razor\v3.0\<name>    
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\WEB\RAZOR\V3.0\<name>\<name> 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\WindowsPhone\<name>    
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\WINDOWSPHONE\<name>\<name> 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web Tools\Project\<name>   
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\MICROSOFT\WEB TOOLS\PROJECT\<name>\<name>    
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\<name>    
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\<name>\<name> 
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\DataDesign\<name>  
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\DATADESIGN\<name>\<name>   

但是程序集实际上在文件夹中:

C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\<company>\<plugin>\1.0

0 个答案:

没有答案