4
$\begingroup$

After we Needs["NETLink`"] and InstallNET[];,we can use load many .net packages by LoadNETType,such as we can

LoadNETType["System.Windows.Forms.Clipboard"]

Then we can use some extra functions from Clipboard`,and we can check it with Names

Names["Clipboard`*"]

{Clipboard`Clear,Clipboard`ContainsAudio,Clipboard`ContainsData,Clipboard`ContainsFileDropList,Clipboard`ContainsImage,Clipboard`ContainsText,Clipboard`Equals,Clipboard`GetAudioStream,Clipboard`GetData,Clipboard`GetDataObject,Clipboard`GetFileDropList,Clipboard`GetImage,Clipboard`GetText,Clipboard`ReferenceEquals,Clipboard`SetAudio,Clipboard`SetData,Clipboard`SetDataObject,Clipboard`SetFileDropList,Clipboard`SetImage,Clipboard`SetText}

But how to find all .net packages in my local disk?

$\endgroup$
5
$\begingroup$

We can get a list of all .NET types that can be loaded using LoadNETType like this:

Needs["NETLink`"]
InstallNET[];

LoadedNETAssemblies[] //
Map[GetAssemblyObject[#]@GetTypes[]&] //
Flatten //
Map[#@FullName&] //
Sort //
Short[#, 5]&

(*
   { Accessibility.AnnoScope,Accessibility.CAccPropServices,
     Accessibility.CAccPropServicesClass,Accessibility.IAccessible,
     Accessibility.IAccessibleHandler,Accessibility.IAccIdentity,
     Accessibility.IAccPropServer,
     <<11369>>,
     Wolfram.NETLink.UI.ConsoleWindow+TextBoxStream,
     Wolfram.NETLink.UI.DoubleBufferedPanel,
     Wolfram.NETLink.UI.MathPictureBox,Wolfram.NETLink.UI.NamespaceDoc,
     Wolfram.NETLink.Utils,Wolfram.NETLink.WrappedKernelLink,
     Wolfram.NETLink.YieldFunction
   }
*)

To find all DLLs that can be loaded by LoadNETAssembly, we must perform a file system scan. For example, to find all .NET assemblies under the Windows .NET framework directory:

LoadNETType["System.Reflection.AssemblyName", AllowShortContext->False];

FileNames["*.dll", "c:\\windows\\microsoft.net\\framework", Infinity] //
Select[Quiet[Check[System`Reflection`AssemblyName`GetAssemblyName[#]; True, False]]&] //
Sort //
Column

(*
  { "c:\\windows\\microsoft.net\\framework\\v2.0.50727\\Accessibility.dll",
    "c:\\windows\\microsoft.net\\framework\\v2.0.50727\\cscompmgd.dll",
    <<577>>,
    "c:\\windows\\microsoft.net\\framework\\v4.0.30319\\WPF\\WindowsFormsIntegration.dll",
    "c:\\windows\\microsoft.net\\framework\\v4.0.30319\\XamlBuildTask.dll",
    "c:\\windows\\microsoft.net\\framework\\v4.0.30319\\XsdBuildTask.dll"
  }
*)

Once we have loaded an assembly or type, we can use NETTypeInfo to get more information:

"c:\\windows\\microsoft.net\\framework\\v4.0.30319\\Microsoft.Build.Engine.dll" //
LoadNETAssembly //
NETTypeInfo

NETTypeInfo screenshot

"Microsoft.Build.BuildEngine.FileLogger" //
LoadNETType //
NETTypeInfo

NETTypeInfo screenshot

$\endgroup$
  • $\begingroup$ Why your code cannot work when I write LoadNETAssembly[ FileNameJoin[{$TopDirectory, "\\SystemFiles\\Links\\OpenCVLink\\LibraryResources\\Windows-x86-\ 64\\opencv_stitching310.dll"}]] $\endgroup$ – yode Sep 6 '17 at 12:53
  • $\begingroup$ @yode That DLL does not contain a managed .NET assembly. Note that the DLL does not pass the GetAssemblyName test. $\endgroup$ – WReach Sep 6 '17 at 16:13
  • $\begingroup$ Is there any method to glance that dll file by our Mathematica? $\endgroup$ – yode Sep 6 '17 at 16:32
  • $\begingroup$ @yode I am not aware of any easy method that uses only Mathematica. We could use Dependency Walker to view the symbol table. Or we could just read the documentation :) $\endgroup$ – WReach Sep 6 '17 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.