导出失败的原因是:无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。

发布于 2024-12-03 14:19:13 字数 138 浏览 0 评论 0原文

每次我将代码发布到另一台服务器时,都会收到以下错误 导出失败的原因是:无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。

这非常令人沮丧,我已经检查并确保包含所有项目参考文件......任何帮助将不胜感激!

Everytime I publish my code to another server, I get the following error
Failed to export due to: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

This is very frustrating, I have already checked and made sure all the project reference files are included.... Any help would be appreciated!

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

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

发布评论

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

评论(2

呢古 2024-12-10 14:19:14

我在使用 AutoFac 时遇到了这个问题。基本上我有这行代码,并且得到了与您相同的错误:

return builder.Build();

异常没有告诉您任何信息!因此,您需要按照其说明合并“LoaderExceptions”。我想出了这个效果非常好的方法,并直接指出了缺少的 DLL:

        try
        {
            return builder.Build();
        }
        catch (Exception ex)
        {
            if (ex is ReflectionTypeLoadException)
            {
                var typeLoadException = ex as ReflectionTypeLoadException;
                var loaderExceptions = typeLoadException.LoaderExceptions;
                throw new AggregateException(typeLoadException.Message, loaderExceptions);
            }
            throw;
        }

现在,在异常中我得到了一堆有用的信息,但最重要的是我缺少的 DLL:“(Inner Exception #0) System. IO.FileNotFoundException:无法加载文件或程序集“System.Web.Mvc,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其之一系统找不到指定的文件。
文件名:'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'"

我发现System.Web.MVC被这个项目引用的一个项目引用了。所以这个项目并不直接需要但它的一个依赖项确实如此。

在您的代码中添加这样的 try/catch ,我想您会省去很多麻烦

I had this issue using AutoFac. Basically I had this line of code and was getting the same error as you:

return builder.Build();

The exception tells you nothing as you know! So you need to incorporate the "LoaderExceptions" as it says. I came up with this that works really well and pointed me straight away to the DLL that was missing:

        try
        {
            return builder.Build();
        }
        catch (Exception ex)
        {
            if (ex is ReflectionTypeLoadException)
            {
                var typeLoadException = ex as ReflectionTypeLoadException;
                var loaderExceptions = typeLoadException.LoaderExceptions;
                throw new AggregateException(typeLoadException.Message, loaderExceptions);
            }
            throw;
        }

Now in the exception I get a bunch of useful information but most importantly the DLL I was missing: "(Inner Exception #0) System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'"

I found that System.Web.MVC was referenced by a project that this project referenced. So this project did not directly need it but one of it's dependencies did.

Put a try/catch like that around your code and I think you will save yourself a lot of pain.

Cheers.

一张白纸 2024-12-10 14:19:14

我在 Autofac Build() 周围使用 nootn 的 try catch 代码并收到以下错误,

Could not load file or assembly 'EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

这是因为我使用的是 MVC4 VS2012 模板,并且默认情况下 EntityFramework 引用默认指向 EF 5 rc。因此,我Uninstall-package EntityFramework,然后Install-package EntityFramework 安装 EF4.3。现在正在工作。谢谢你。

I use the nootn's try catch code around the Autofac Build() and got the following error,

Could not load file or assembly 'EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

This was because I was using MVC4 VS2012 template and by default the EntityFramework reference was pointing to EF 5 rc by default. So I Uninstall-package EntityFramework and then Install-package EntityFramework which install EF4.3. It's working now. Thank you nootn.

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