本文整理汇总了C#中System.ResolveEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# ResolveEventArgs类的具体用法?C# ResolveEventArgs怎么用?C# ResolveEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResolveEventArgs类属于System命名空间,在下文中一共展示了ResolveEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveAssembly
/// <summary>
/// Handler to the ApplicationDomain's AssemblyResolve event.
/// If an assembly's location cannot be resolved, an exception is
/// thrown. Failure to resolve an assembly will leave Dynamo in
/// a bad state, so we should throw an exception here which gets caught
/// by our unhandled exception handler and presents the crash dialogue.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
public static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
try
{
// First check the core path
string assemblyPath = Path.Combine(DynamoPathManager.Instance.MainExecPath, new AssemblyName(args.Name).Name + ".dll");
if (File.Exists(assemblyPath))
{
return Assembly.LoadFrom(assemblyPath);
}
// Then check all additional resolution paths
foreach (var addPath in DynamoPathManager.Instance.AdditionalResolutionPaths)
{
assemblyPath = Path.Combine(addPath, new AssemblyName(args.Name).Name + ".dll");
if (File.Exists(assemblyPath))
{
return Assembly.LoadFrom(assemblyPath);
}
}
return null;
}
catch (Exception ex)
{
throw new Exception(string.Format("There location of the assembly, {0} could not be resolved for loading.", args.Name), ex);
}
}
示例2: CurrentDomain_AssemblyResolve
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
Assembly asm;
if (!AssemblyCache.TryGetValue(args.Name, out asm))
{
var name = args.Name;
var index = name.IndexOf(",");
if (index > 0)
name = name.Substring(0, index);
foreach (var path in BinPath)
{
var filename = name + ".dll";
var filepath = Path.Combine(path, filename);
if (!File.Exists(filepath))
{
filepath = Path.ChangeExtension(filepath, ".exe");
}
if (File.Exists(filepath))
{
asm = Assembly.LoadFrom(filepath);
if (asm != null)
{
AssemblyCache[asm.FullName] = asm;
Console.WriteLine("Assembly resolver found assembly "+asm.Location);
break;
}
}
}
}
return asm;
}
示例3: OnAssemblyResolve
public Assembly OnAssemblyResolve(object sender,
ResolveEventArgs args)
{
if (!(sender is AppDomain))
return null;
string[] pathList = new[]
{
Path.Combine(Directory.GetCurrentDirectory(), "bin"),
Path.Combine(Directory.GetCurrentDirectory(), PathToSearch),
Path.Combine(Directory.GetCurrentDirectory(),
Path.Combine(PathToSearch, "Scripts")),
Directory.GetCurrentDirectory(),
};
string assemblyName = args.Name;
if (assemblyName.IndexOf(",") != -1)
assemblyName = args.Name.Substring(0, args.Name.IndexOf(","));
foreach (string s in pathList)
{
string path = Path.Combine(s, assemblyName) + ".dll";
if (File.Exists(path))
return Assembly.Load(AssemblyName.GetAssemblyName(path));
}
return null;
}
示例4: Resolve
static Assembly Resolve(object sender, ResolveEventArgs e) {
byte[] b = Encoding.UTF8.GetBytes(new AssemblyName(e.Name).FullName.ToUpperInvariant());
Stream m = null;
if (b.Length + 4 <= key.Length) {
for (int i = 0; i < b.Length; i++)
b[i] *= key[i + 4];
string n = Convert.ToBase64String(b);
m = Assembly.GetEntryAssembly().GetManifestResourceStream(n);
}
if (m != null) {
var d = new uint[m.Length >> 2];
var t = new byte[0x100];
int r;
int o = 0;
while ((r = m.Read(t, 0, 0x100)) > 0) {
Buffer.BlockCopy(t, 0, d, o, r);
o += r;
}
uint s = 0x6fff61;
foreach (byte c in b)
s = s * 0x5e3f1f + c;
GCHandle h = Decrypt(d, s);
var f = (byte[])h.Target;
Assembly a = Assembly.Load(f);
Array.Clear(f, 0, f.Length);
h.Free();
Array.Clear(d, 0, d.Length);
return a;
}
return null;
}
示例5: AssemblyResolve
Assembly AssemblyResolve(object sender, ResolveEventArgs args) {
var assembly = Get(args.Name);
if (assembly != null)
return assembly;
var asmName = new AssemblyName(args.Name);
foreach (var path in assemblySearchPaths) {
foreach (var ext in assemblyExtensions) {
try {
var filename = Path.Combine(path, asmName.Name + ext);
if (!new FileInfo(filename).Exists)
continue;
AddConfigFile(filename + ".config");
return AddAssembly(Assembly.LoadFile(filename));
}
catch (IOException) {
}
catch (BadImageFormatException) {
}
catch (ArgumentException) {
}
catch (NotSupportedException) {
}
catch (UnauthorizedAccessException) {
}
catch (System.Security.SecurityException) {
}
}
}
return null;
}
示例6: Resolver
public Assembly Resolver(object sender, ResolveEventArgs args)
{
lock (this)
{
Assembly assembly;
AssemblyName askedAssembly = new AssemblyName(args.Name);
string[] fields = args.Name.Split(',');
string name = fields[0];
string culture = fields[2];
// failing to ignore queries for satellite resource assemblies or using [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
// in AssemblyInfo.cs will crash the program on non en-US based system cultures. detailed discussion: http://connect.microsoft.com/VisualStudio/feedback/details/526836/wpf-appdomain-assemblyresolve-being-called-when-it-shouldnt
if (name.EndsWith(".resources") && !culture.EndsWith("neutral")) return null;
string resourceName = string.Format("BlizzTV.Assets.Assemblies.{0}.dll", askedAssembly.Name);
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
if (stream == null)
{
LogManager.Instance.Write(LogMessageTypes.Fatal, string.Format("Can not resolve asked assembly: {0}", askedAssembly));
MessageBox.Show(i18n.CanNotLoadRequiredAssembliesMessage, i18n.CanNotLoadRequiredAssembliesTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(-1);
}
byte[] assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
assembly = Assembly.Load(assemblyData);
}
LogManager.Instance.Write(LogMessageTypes.Trace, "Loaded embedded assembly: " + askedAssembly);
return assembly;
}
}
示例7: OnAssemblyResolve
private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
lock (syncRoot)
{
if (checkedAssemblies.Add(args.Name))
{
var assemblyName = new AssemblyName(args.Name);
if (!assemblyName.Name.EndsWith(".resources"))
{
var stream = typeof(AssemblyResolver).Assembly.GetManifestResourceStream(typeof(AssemblyResolver), assemblyName.Name + ".pkg");
if (stream != null)
{
using (var package = Package.Open(stream))
{
var partUri = PackUriHelper.CreatePartUri(new Uri(assemblyName.Name + ".dll", UriKind.Relative));
if (package.PartExists(partUri))
{
var part = package.GetPart(partUri);
var ms = new MemoryStream();
part.GetStream().CopyTo(ms);
return Assembly.Load(ms.ToArray());
}
}
}
}
}
return null;
}
}
示例8: OnAppDomainAssemblyResolve
static Assembly OnAppDomainAssemblyResolve(object sender, ResolveEventArgs args)
{
if (assemblyResolveReentrant)
{
return null;
}
assemblyResolveReentrant = true;
try
{
try
{
return Assembly.Load(args.Name);
}
catch (FileNotFoundException)
{
return null;
}
catch (FileLoadException)
{
return null;
}
catch (BadImageFormatException)
{
return null;
}
}
finally
{
assemblyResolveReentrant = false;
}
}
示例9: AssemblyResolve
Assembly AssemblyResolve(object sender, ResolveEventArgs e)
{
AssemblyName name = new AssemblyName(e.Name);
LoggingService.Debug("ProjectContentRegistry.AssemblyResolve " + e.Name);
string path = Path.Combine(lookupDirectory, name.Name);
if (File.Exists(path + ".dll")) {
return Assembly.ReflectionOnlyLoadFrom(path + ".dll");
}
if (File.Exists(path + ".exe")) {
return Assembly.ReflectionOnlyLoadFrom(path + ".exe");
}
if (File.Exists(path)) {
return Assembly.ReflectionOnlyLoadFrom(path);
}
try {
LoggingService.Debug("AssemblyResolve trying ReflectionOnlyLoad");
return Assembly.ReflectionOnlyLoad(e.Name);
} catch (FileNotFoundException) {
LoggingService.Warn("AssemblyResolve: ReflectionOnlyLoad failed for " + e.Name);
// We can't get the assembly we want.
// But propably we can get a similar version of it.
DomAssemblyName fixedName = GacInterop.FindBestMatchingAssemblyName(e.Name);
LoggingService.Info("AssemblyResolve: FixedName: " + fixedName);
return Assembly.ReflectionOnlyLoad(fixedName.FullName);
}
}
示例10: EmbeddedAssemblyResolver
private static Assembly EmbeddedAssemblyResolver(object sender, ResolveEventArgs args)
{
try
{
var assemblyName = new AssemblyName(args.Name);
String resourceName = Assembly.GetExecutingAssembly().FullName.Split(',').First() + "." + assemblyName.Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
if (stream != null)
{
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
if (Array.Exists(UnmanagedAssemblies, element => element.Equals(assemblyName.Name)))
{
String tempFile = Path.GetTempFileName();
File.WriteAllBytes(tempFile, assemblyData);
Console.WriteLine("[" + Thread.CurrentThread.ManagedThreadId + "-" + Thread.CurrentThread.Name + "] Loading assembly " + assemblyName.Name + " from " + tempFile);
return Assembly.LoadFile(tempFile);
}
else
{
return Assembly.Load(assemblyData);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + (ex.InnerException != null ? " : " + ex.InnerException.Message : ""), "Program Failed to access Assembly " + args.Name,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return null;
}
示例11: OrigoDomainOnAssemblyResolve
private Assembly OrigoDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
Assembly assembly = Assembly.Load(args.Name);
if (assembly != null)
return assembly;
}
catch
{
// ignore load error
}
// *** Try to load by filename - split out the filename of the full assembly name
// *** and append the base path of the original assembly (ie. look in the same dir)
// *** NOTE: this doesn't account for special search paths but then that never
// worked before either.
string[] parts = args.Name.Split(',');
string file = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + parts[0].Trim() +
".dll";
if (File.Exists(file))
{
return Assembly.LoadFrom(file);
}
return null;
}
示例12: ResolveAssembly
Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
var appDirectory = AppDomain.CurrentDomain.BaseDirectory;
var modulesDirectory = Path.Combine(appDirectory, "Modules");
var filename = Path.Combine(modulesDirectory, new AssemblyName(args.Name).Name + ".dll");
return Assembly.Load(File.ReadAllBytes(filename));
}
示例13: CurrentDomain_AssemblyResolve
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
//
if (!args.Name.Contains("SDNSAPI"))
return null;
//
string connectorKeyName = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{33A002DC-D590-4527-B98E-3B9D6F4FC5DC}";
string connectorLocation = String.Empty;
//
if (PInvoke.RegistryHive.HKLM.SubKeyExists_x86(connectorKeyName))
{
connectorLocation = PInvoke.RegistryHive.HKLM.GetSubKeyValue_x86(connectorKeyName, "InstallLocation");
}
//
if (String.IsNullOrEmpty(connectorLocation))
{
Log.WriteInfo("SimpleDNS API library location is either null or empty");
return null;
}
//
string assemblyFile = Path.Combine(connectorLocation, args.Name.Split(',')[0] + ".dll");
//
Log.WriteInfo(assemblyFile);
//
if (!File.Exists(assemblyFile))
{
Log.WriteInfo("SimpleDNS API library could not be found or does not exist");
return null;
}
//
return Assembly.LoadFrom(assemblyFile);
}
示例14: Resolver
static System.Reflection.Assembly Resolver(object sender, ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Load required DLL form a embeded Ressources
Assembly a1 = Assembly.GetExecutingAssembly(); // Get Executing Assembly
//Find the Name of the missing Dll to Load
string Name = a1.GetName().Name + ".DLL." + args.Name.Split(',')[0];
//Get a List of Embeded Ressources
string[] str = a1.GetManifestResourceNames();
byte[] block = null;
for (int i = 0; i < str.Length; i++)
{
if (str[i].StartsWith(Name))//Does not check for the Extension, SO multiple extension are a not OK. Or if the File Name does not match the Namespace
{
Stream s = a1.GetManifestResourceStream(str[i]);
block = new byte[s.Length];
s.Read(block, 0, block.Length);
break;
}
}
Assembly a2 = Assembly.Load(block);
return a2;
}
示例15: CurrentDomain_AssemblyResolve
// This method loads Assemblys such as the SharpZipLib which is needed for bz2-files.
// But only when they're needed. That makes it so special...
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (!args.Name.Contains("ICSharpCode.SharpZipLib"))
{
return null;
}
Assembly result = null;
using (Stream embedded = Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(Program).Namespace + ".ICSharpCode.SharpZipLib.dll"))
{
byte[] buffer = new byte[embedded.Length];
int length = buffer.Length;
int offset = 0;
while (length > 0)
{
int read = embedded.Read(buffer, offset, length);
if (read == 0)
{
break;
}
length -= read;
offset += read;
}
result = Assembly.Load(buffer);
}
return result;
}