开发者

Working with dependencies using Reflection

开发者 https://www.devze.com 2023-02-16 15:11 出处:网络
I\'m trying to read all dependencies of one dll file in a known path. To do this I\'m using reflection as this code shows:

I'm trying to read all dependencies of one dll file in a known path. To do this I'm using reflection as this code shows:

        For Each AsmName As AssemblyName In asm.GetReferencedAssemblies()
        Try
            Log += AsmName.Name & " : " & [Assembly].ReflectionOnlyLoad(AsmName.ToString).Location & vbCrLf
        Catch ex As Exception
            Log += AsmName.Name & " : NOT FOUND." & vbCrLf
        End Try
    Next

To test this I've developed a dll in VB NET with a few dependeces from other dll files made by me.

When I pass the file path, I can detect all assemblies which depends the file. But when I try to recover the file path of the dependencie I can find all file path for all dependencies excepts the dll files made by me.

When I run the code I'm obtaining the following log result:

mscorlib : C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll Microsoft.VisualBasic : C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualBasic\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll System.Xml.Linq : C:\WINDOWS\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll System : C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll IM2_DataFile : NOT FOUND. System.Data : C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll IM2_DataRow : NOT FOUND. System.Drawing : C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll IM2_DataProviderTools : NOT FOUND. System.Windows.Forms : C:\WINDOWS\assembly\GAC_MS开发者_开发技巧IL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll Telerik.WinControls.UI : C:\WINDOWS\assembly\GAC_MSIL\Telerik.WinControls.UI\2009.2.9.729__5bb2a467cbec794e\Telerik.WinControls.UI.dll IM2_DataRowPanel : NOT FOUND. Telerik.WinControls.GridView : C:\WINDOWS\assembly\GAC_MSIL\Telerik.WinControls.GridView\2009.2.9.729__5bb2a467cbec794e\Telerik.WinControls.GridView.dll IM2_Language_Controller : NOT FOUND. System.Core : C:\WINDOWS\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll Telerik.WinControls : C:\WINDOWS\assembly\GAC_MSIL\Telerik.WinControls\2009.2.9.729__5bb2a467cbec794e\Telerik.WinControls.dll IM2_CommonTools : NOT FOUND.

All files that starts by IM2_ are the files what i want to get the path.

I've observed that the files wich can't find has PublicKeyToken=null. I've googled by this and it's because I didn't serializaed the classes when were compiled.

Please could anyone help me? The target is get all filepath of all dependencies of a dll file.

Thanks in advance.


It looks like you're trying to load the assemblies using on the assembly name (NOT the full file/path to the assembly). For assemblies registered in the GAC (Global Assembly cache) that'll work, but +your+ assemblies probably aren't registered in the GAC, so they can't be loaded in the same way. I'll have to dig around for an example of how to load an assembly via an actual filename.

0

精彩评论

暂无评论...
验证码 换一张
取 消