2017-01-22 1 views
1

J'ai ajouté Microsoft.Owin.Host.SystemWeb à un projet Asp.Net Formulaires Web existants (à utiliser Azure authentification Active Directory) et obtenirErreur OwinBuilder.GetAppStartup "Impossible de charger le fichier ou l'assemblage" - comment trouver l'endroit où l'assembly est appelé?

[FileNotFoundException: Impossible de charger le fichier ou l'assemblage « PostSharp .Sdk, Version = 2.1.0.0, Culture = neutre, PublicKeyToken = b13fd38b8f9c99d7 'ou l'une de ses dépendances. Le système ne peut pas trouver le fichier spécifié.]
System.ModuleHandle.ResolveType (module RuntimeModule, Int32 typeToken, IntPtr * typeInstArgs, Int32 typeInstCount, IntPtr * methodInstArgs, Int32 methodInstCount, type ObjectHandleOnStack) +0
de System.ModuleHandle .ResolveTypeHandleInternal (module RuntimeModule, Int32 typeToken, RuntimeTypeHandle [] typeInstantiationContext, RuntimeTypeHandle [] methodInstantiationContext) 191
System.Reflection.RuntimeModule.ResolveType (Int32 MetadataToken, type [] genericTypeArguments, du type [] genericMethodArguments) 162
System.Reflectio n.CustomAttribute.FilterCustomAttributeRecord (CustomAttributeRecord caRecord, la portée MetadataImport, Assemblée & lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, objet [] attributs, derivedAttributes IList, RuntimeType & attributeType, & IRuntimeMethodInfo cteur, booléen & ctorHasParameters, booléens & isVarArg) +148
System.Reflection.CustomAttribute.GetCustomAttributes (RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, booléen isDecoratedTargetSecurityTransparent) +604 System.Reflection.CustomAttribute.GetCustomAttributes (RuntimeAssembly d'assemblage , RuntimeType caType) 144
Owin.Loader.DefaultLoader.SearchForStartupAttribute (String friendlyName, IList 1 errors, Boolean& conflict) +189
Owin.Loader.DefaultLoader.GetDefaultConfiguration(String friendlyName, IList
1 erreurs) 68
Owin.Loader.DefaultLoader.LoadImplementation (String startupName, IList 1 errorDetails) +89 Owin.Loader.DefaultLoader.Load(String startupName, IList 1) ErrorDetails 30
Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() 165
Microsoft.Owin.Host .SystemWeb.OwinHttpModule .InitializeBlueprint() 37 System.Threading.LazyInitializer.EnsureInitializedCore (T & cible, & booléenne initialisé, objet & SyncLock, Func`1 valueFactory) 137
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init (HttpApplication contexte) +172
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS (IntPtr appContext, HttpContext contexte, MethodInfo [] Chariot) +618
System.Web.HttpApplication.InitSpecial (HttpApplicationState état, MethodInfo [] Chariot, IntPtr appContext , Contexte HttpContext) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance (IntPtr appContext, contexte HttpContext) +402
System.Web.Hosting.PipelineRuntime.InitializeApplication (IntPtr appContext) +343

Comme je comprends Owin.Loader.DefaultLoader.SearchForStartupAttribute utilise la réflexion et ne pouvait pas charger un attribut, mais il ne signale pas quel attribut il scanne et où il se trouve.

Notre projet utilise PostSharp pour la mise en cache et la journalisation, mais (pour autant que je sache) nous utilisons version = "4.3.21" et un attribut fait référence à "3.0.26.9", mais de toute façon devrait rediriger vers 4.3.21 dû à

<bindingRedirect oldVersion="0.0.0.0-4.3.21.0" newVersion="4.3.21.0" /> 

J'ai recherché le code source pour "PostSharp.Sdk", mais je n'ai trouvé aucune référence.

Le coup d'œil rapide lors du démontage avec JetBrain DotPeek n'a pas non plus fait référence à PostSharp.Sdk. Notez que Version = 2.1 est très ancien.

Il existe des liens http://support.sharpcrafters.com/discussions/problems/2275-postsharp-is-not-compatible-with-microsoftowinsecurity-latest-version et issue with PostSharp cannot find assembly for system.web.mvc, version=3.0.0.0 when no projects reference it, qui semblent similaires, mais ils ont un problème inverse: PostSharp n'a pas pu résoudre les dlls MVC ou Owin.

Quelqu'un pourrait-il suggérer comment identifier quel attribut (et sur quelle classe) fait référence à PostSharp.Sdk?

Je considère faire moi-même ce que SearchForStartupAttribute fait -scan le (s) assembly (s) pour les attributs personnalisés et consigner tout ce qui a été trouvé. Des idées meilleures/plus simples?

+0

Une chance dans ex.InnerException? – Zen

Répondre

1

Merci à l'Open Source, je trouve le code source https://katanaproject.codeplex.com/SourceControl/latest#src/Owin.Loader/DefaultLoader.cs et copié localement la classe (avec un couple de classes internes utilisés par DefaultLoader). Code actuel ne tient pas seulement CustomAttributeFormatException, j'ai Trace, puis ignorer toutes les erreurs

private Tuple<Type, string> SearchForStartupAttribute(string friendlyName, IList<string> errors, ref bool conflict) 
foreach (var assembly in _referencedAssemblies) 
      { 
       object[] attributes; 
       try 
       { 
        attributes = assembly.GetCustomAttributes(inherit: false); 
       } 
      // catch (CustomAttributeFormatException) 
      // { 
      //  continue; 
      // } 
       catch (Exception exc) 
       { 
        string message = "In " + assembly.ToString(); 
        System.Diagnostics.Trace.WriteLine(message + " " + exc.ToString()); 
        continue; 
       } 

J'ai appelé la classe de Global (global.asax publique)

var loader = new Owin.Loader.Debug.DefaultLoader(); 
    IList<string> errorDetauls = new List<string>(); 
    loader.Load("Startup", errorDetauls); 

Il m'a montré, ce qui a causé DLL le problème, et j'ai supprimé la référence. La DLL faisait référence à l'ancienne bibliothèque PostSharp non utilisée, mais elle ne causait aucun dommage jusqu'à maintenant. SearchForStartupAttribute scanne toutes les DLL situées dans le dossier bin et fragiles aux problèmes tels que les DLL de référence manquantes. J'ai soumis une suggestion "DefaultLoader.SearchForStartupAttribute should be tolerant to unrelated errors"

+0

Merci pour l'explication de ce qui était la cause. –