エラー メッセージ「要求されたタイプの 1 つ以上をロードできません。詳細については LoaderExceptions プロパティを取得してください。」質問する

エラー メッセージ「要求されたタイプの 1 つ以上をロードできません。詳細については LoaderExceptions プロパティを取得してください。」質問する

私はアプリケーションを開発しましたエンティティフレームワーク、SQL Server 2000、Visual Studio 2008、および Enterprise Library。

ローカルではまったく問題なく動作しますが、プロジェクトをテスト環境にデプロイすると、次のエラーが発生します。

要求されたタイプの 1 つ以上をロードできません。詳細については LoaderExceptions プロパティを取得してください。

スタック トレース: System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark)

System.Reflection.Assembly.GetTypes() で

System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadTypesFromAssembly(LoadingContext コンテキスト) で

System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.InternalLoadAssemblyFromCache(LoadingContext コンテキスト) で

System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadAssemblyFromCache(アセンブリ アセンブリ、ブール値 loadReferencedAssemblies、辞書2 knownAssemblies, Dictionary2& typesInLoading、リスト `1& errors)

System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection、Assembly assembly、Boolean loadReferencedAssemblies) で

System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyForType(型タイプ)

System.Data.Metadata.Edm.MetadataWorkspace.LoadAssemblyForType(Type type、Assembly callingAssembly) で

System.Data.Objects.ObjectContext.CreateQuery[T](String queryString、ObjectParameter[] パラメータ)

Entity Framework に問題があるようですが、修正方法の手がかりはありますか?

ベストアンサー1

このエラーには、本当の魔法の解決策はありません。重要なのは、問題を理解するためのすべての情報を把握することです。動的に読み込まれたアセンブリに参照アセンブリがない可能性が最も高いです。そのアセンブリは、アプリケーションの bin ディレクトリにある必要があります。

このコードを使用して、何が不足しているかを判断します。

using System.IO;
using System.Reflection;
using System.Text;

try
{
    //The code that causes the error goes here.
}
catch (ReflectionTypeLoadException ex)
{
    StringBuilder sb = new StringBuilder();
    foreach (Exception exSub in ex.LoaderExceptions)
    {
        sb.AppendLine(exSub.Message);
        FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
        if (exFileNotFound != null)
        {                
            if(!string.IsNullOrEmpty(exFileNotFound.FusionLog))
            {
                sb.AppendLine("Fusion Log:");
                sb.AppendLine(exFileNotFound.FusionLog);
            }
        }
        sb.AppendLine();
    }
    string errorMessage = sb.ToString();
    //Display or log the error based on your application.
}

おすすめ記事