by
0
5
432
0
Top 5% !
Popular
Easy-to-find
Specified
OpenSource
Popularity: 225480th place

Published on:

LanguageCSharp
LicenseMIT_X11
OSWindows

TryInitializeWindowsRuntimeTypeWithAssembly: Initialize a type defined in an assembly that is not loaded by default

<summary>
Initialize a type defined in an assembly that is not loaded by default
</summary>
<param name="assemblyName">Assembly to be loaded to fetch the type</param>
<param name="assemblyQualifiedTypeName">name of type to be fetched from the loaded assembly</param>
<returns>null if type cannot be loaded</returns>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/290976/TryInitializeWindowsRuntimeTypeWithAssem?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Threading.Tasks; /// <summary> /// Initialize a type defined in an assembly that is not loaded by default /// </summary> /// <param name="assemblyName">Assembly to be loaded to fetch the type</param> /// <param name="assemblyQualifiedTypeName">name of type to be fetched from the loaded assembly</param> /// <returns>null if type cannot be loaded</returns> protected static Type TryInitializeWindowsRuntimeTypeWithAssembly(string assemblyName, string assemblyQualifiedTypeName) { try { Assembly assembly = Assembly.Load(assemblyName); return assembly.GetType(assemblyQualifiedTypeName); } catch (System.IO.IOException) { return null; } // if the type can't be loaded or any dependent assembly was not found, return false as this is a legacy platform. catch (TypeLoadException) { return null; } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus