呼叫汇集功能时的抗试验错误

发布于 2025-02-12 04:04:28 字数 1719 浏览 0 评论 0原文

我正在将自己的自定义加载程序添加到汇编整理中,以在.NET库中加载一些嵌入式资源;

AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => { return Domain.Assemblies.LoadResource(e.Name, System.Reflection.Assembly.GetExecutingAssembly()); };
        public static System.Reflection.Assembly LoadResource(string fileName, System.Reflection.Assembly assembly)
        {
            fileName = assembly.GetName().Name + "." + fileName.Split(',')[0] + ".dll";
            var resFilestream = assembly.GetManifestResourceStream(fileName);
            byte[] ba = new byte[resFilestream.Length];
            resFilestream.Read(ba, 0, ba.Length);
            var byteArray = ba;
            resFilestream.Close();
            resFilestream.Dispose();
            return System.Reflection.Assembly.Load(byteArray);
        }

这在许多不同的环境(Winforms,Azure Apps/WebJobs/functions)中正常工作,但是当我尝试在ASP.NET(4.7.2)MVC站点中执行此代码时,它会破坏反诉讼?这个问题似乎是关联的,一个dll无法正确加载,

TypeInitializationException: The type initializer for 'System.Web.Helpers.Claims.ClaimsIdentityConverter' threw an exception.
FileLoadException: Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))
NullReferenceException: Object reference not set to an instance of an object.

如果我删除对汇编加载dll的类初始化类的对象,则会导致三个单独的错误,则该站点无误。如果我把它放回原处,就会破裂。我还尝试将代码从Global.Asax移动到在线C#,但是一旦您运行它,下一个带有伪造令牌的页面的负载将以相同的方式错误。

更新 在运行Fusion ++检查DLL加载时,我可以看到错误的DLL实际上在两种情况下都具有完全相同的负载故障(相当通用的“找不到汇编”)。但是,只有当我加载dll时,它才会出现一个例外。

I'm adding my own custom loader to AssemblyResolve to load some embedded resources in a .net library;

AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => { return Domain.Assemblies.LoadResource(e.Name, System.Reflection.Assembly.GetExecutingAssembly()); };
        public static System.Reflection.Assembly LoadResource(string fileName, System.Reflection.Assembly assembly)
        {
            fileName = assembly.GetName().Name + "." + fileName.Split(',')[0] + ".dll";
            var resFilestream = assembly.GetManifestResourceStream(fileName);
            byte[] ba = new byte[resFilestream.Length];
            resFilestream.Read(ba, 0, ba.Length);
            var byteArray = ba;
            resFilestream.Close();
            resFilestream.Dispose();
            return System.Reflection.Assembly.Load(byteArray);
        }

This works fine in many different environments(Winforms, Azure apps/webjobs/functions), but when I try to execute this code within an asp.net(4.7.2) MVC site, it breaks the anti-forgery? The issue seems to be related a DLL not being loaded correctly, and causes three seperate errors

TypeInitializationException: The type initializer for 'System.Web.Helpers.Claims.ClaimsIdentityConverter' threw an exception.
FileLoadException: Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))
NullReferenceException: Object reference not set to an instance of an object.

If I remove the object initialising the class within the assembly loading dll, the site works with no error. If I put it back in it breaks. I also tried moving the code from the global.asax to in-line c#, but as soon as you run it, the next load of a page with a forgery token will error in the same way.

UPDATE
Having run Fusion++ to check the DLL loading, I can see that the DLL that is erroring actually has the exact same load failure in both situations(A fairly generic "Could not find assembly"). But only when I load my DLL does it present itself as an exception.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼疼热情 2025-02-19 04:04:28

问题不是您的代码,而是此依赖性Microsoft.IdentityModel:要存在这种依赖性,并且可能将其消费到Windows客户端环境中,可能需要在GAC(Global Assembly Cache)上安装DLL和依赖性;如果Microsoft.InderityModel不存在于GAC文件夹中,则代码将返回错误。

可以使用Visual Studio或Windows功能安装 Windows Windows Identity Foundation 3.5 ,可以安装 Windows Identity Foundation 3.5

The problem is not with your code, but this dependecy Microsoft.IdentityModel: to exist this dependency and possibilty to consume into Windows client environment, probally the dll and dependecies needs to be installed at GAC (Global Assembly Cache); if Microsoft.IdentityModel not exists into GAC Folder, the code returns the error.

It's possible to install the Windows Identity Foundation 3.5 with Visual Studio or from Windows Features install the Windows Identity Foundation 3.5.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文