首页 \ 问答 \ 为什么AssemblyResolver即使在加载dll(manualy)时也会触发?(Why AssemblyResolver fire even when dll is loaded (manualy)?)

为什么AssemblyResolver即使在加载dll(manualy)时也会触发?(Why AssemblyResolver fire even when dll is loaded (manualy)?)

我有2个项目的C#解决方案:

  1. DLLTest(控制台应用)
  2. BLib(图书馆)

在DLLTest中,我设置了对BLib的引用,并将Copy Local属性设置为false。
编译解决方案。
将BLib.dll复制到'C:\ BLib.dll'并运行应用程序。
在我的代码的第一步,我从路径'C:\ BLib.dll'加载程序集,然后从那里调用方法。 在从BLib程序集调用方法时触发AssemblyResolver并尝试加载我手动加载的程序集。

我可以做一些应用程序,知道库已经加载,而不是尝试再次加载它?
这是来自BLib项目的BClass.cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLib
{
    public class BClass
    {
        public static void PrintName()
        {
            Console.WriteLine("BLib");
        }
    }
}

这是DLLTest项目的Program.cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace DLLTest
{
    class Program
    {
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            Assembly.LoadFile(@"C:\BLib.dll");
            Console.WriteLine("Loaded assembles:");
            AppDomain.CurrentDomain.GetAssemblies().ToList()
                .ForEach(p => Console.WriteLine(p));
            Console.WriteLine("End list of assembles");
            try
            {
                PrintMessage();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }

        private static void PrintMessage()
        {
            BLib.BClass.PrintName();
        }

        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            Console.WriteLine(args.Name);
            return null;
        }
    }
}

I have C# solution with 2 project:

  1. DLLTest (Console app)
  2. BLib (library)

In DLLTest I set reference to BLib and set Copy Local property to false.
Compile solution.
Copy BLib.dll to 'C:\BLib.dll' and run application.
In first step in my code I load Assembly from path 'C:\BLib.dll' then invoke method from there. On invoking method from BLib assembly fire AssemblyResolver and try load assembly which I loaded before manually.

Can I do something that application to know that the library has already been loaded and not try load it again?
This is BClass.cs file from BLib project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLib
{
    public class BClass
    {
        public static void PrintName()
        {
            Console.WriteLine("BLib");
        }
    }
}

This is Program.cs file from DLLTest project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace DLLTest
{
    class Program
    {
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            Assembly.LoadFile(@"C:\BLib.dll");
            Console.WriteLine("Loaded assembles:");
            AppDomain.CurrentDomain.GetAssemblies().ToList()
                .ForEach(p => Console.WriteLine(p));
            Console.WriteLine("End list of assembles");
            try
            {
                PrintMessage();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }

        private static void PrintMessage()
        {
            BLib.BClass.PrintName();
        }

        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            Console.WriteLine(args.Name);
            return null;
        }
    }
}

原文:https://stackoverflow.com/questions/32178367
更新时间:2022-09-28 21:09

最满意答案

这完全取决于你登录的内容。 这两个选项都是可行的,使用AOL / Google登录的依赖方决定如何处理/连接帐户。


That totally depends on what you're signing in to. Both options are feasible and the Relying Party that uses AOL/Google for login decides how the accounts are treated/connected.

相关问答

更多
  • OpenID Connect 仅支持根据您提供的某些提示(电子邮件,帐户,URL,域名等) 查找您的提供商的发现 ; 它不会为您提供持久标识符,您可以将身份验证委派给您选择的可配置提供程序。 因此,如果您只想使用自定义URI来查找您的提供者,则可以使用Nat给出的方法(除了Google没有做和不能做的最后一点,并假设SO支持发现)。 但是如果你想要真正的委托,那么RP可以使用由OP返回的标识符,这个标识符在你委派的不同的OP上是持久的,那么你不能。 对于StackOverflow,您可能不需要以下任何一种: ...
  • 这完全取决于你登录的内容。 这两个选项都是可行的,使用AOL / Google登录的依赖方决定如何处理/连接帐户。 That totally depends on what you're signing in to. Both options are feasible and the Relying Party that uses AOL/Google for login decides how the accounts are treated/connected.
  • 唯一不同的是。 OpenID Connect和OAuth 2.0之间的授权请求确实是“范围”参数的内容。 OpenID Connect构建于OAuth之上。 触发OpenID Connect流的方法是在授权请求中包含“openid”范围。 OpenID Connect是一种标准化的SSO协议,由各种提供商实施。 不幸的是,LinkedIn还不支持它,请参阅: LinkedIn OpenID Connect提供商吗? 如何与AWS Cognito联合身份一起使用? The only difference wr ...
  • 不,不。 但它做了什么,是指定如何 发现正确端点的URL,使用: GET /.well-known/openid-configuration HTTP/1.1 然后选择authorization_endpoint 。 这里和这里有两个真实世界的例子。 No it doesn't. But what it does do, is specify how to discover the URL of the correct endpoint, using: GET /.well-known/openid-co ...
  • 学术界的标准开源AIM产品是Shibboleth( http://shibboleth.net/ )。 它是一种成熟而强大的产品,在世界各地都在使用。 它通常使用SAML,但有一个OpenID扩展。 https://wiki.shibboleth.net/confluence/display/SHIB2/IdP+OpenID+Configuration 但是我会警告你,配置可能是一件苦差事。 我自己没有使用OpenID扩展。 The standard open source AIM product in a ...
  • 使用/如果使用加密,Connect OP将始终签名,然后加密,如果他们遵循规范。 OpenID Connect Core第2部分说:“如果ID令牌被加密,它必须被签名然后加密”。 第16.14节,签名和加密顺序稍微详细地说了同样的事情。 When/if encryption is used, Connect OPs will always sign and then encrypt, if they are following the specification. Section 2 of OpenID C ...
  • 不推荐使用OpenID代替OpenID Connect。 OAuth 2.0用于授权访问API的应用程序。 所以,使用OpenID Connect。 要使用accounts.xyz.com登录,您需要实现自己的OpenID Connect Provider或其他一些身份验证方法。 OpenID is deprecated in lieu of OpenID Connect. OAuth 2.0 is for delegation to an Application for accessing of APIs ...
  • 是的,Google Identity Toolkit支持OpenID Connect(适用于Google身份提供商)。 虽然Google Identity Toolkit尚未支持Twitter,但我们正在努力添加此类功能并希望尽快推出 - 请继续关注:) 根据你关于AppEngine的OpenID Connect支持的问题,我的理解是目前没有(目前只支持OpenID 2.0,请参阅AppEngine dev文档 )。 希望有所帮助! Yes, Google Identity Toolkit supports ...
  • OpenID是一个开放的规范。 它定义了提供者和消费者之间的接口,它在所有提供者和所有消费者之间是相同的[1]。 这不是关于将您的雅虎身份与您的Google身份相关联,而是让您通过许多其他网站(作为消费者)的任何[2]您的OpenID身份(雅虎,谷歌等作为提供商)来识别自己,而不是创建新用户 - 记住并记住许多密码。 雅虎和谷歌都是提供商(而不是消费者)。 [1]几乎相同,因为它们可能支持额外的扩展。 [2]或者可选择一些。 OpenID is an open specification. It defin ...
  • 我能够找到的唯一允许使用范围“openid”(据我所知的那样需要)的是以下内容,它们都给出了如何设置它的详细步骤,我已使用java客户端验证: 销售队伍: https://developer.salesforce.com/page/Inside_OpenID_Connect_on_Force.com 谷歌: https://developers.google.com/accounts/docs/OAuth2Login#sendauthrequest eBay - 奥利奥项目 - 非常“原始”,并没有真正与e ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)