WCF jette exception FileNotFound pour « System.ServiceModel » lors de la création ServiceHost

StackOverflow https://stackoverflow.com/questions/934980

Question

Je suis en cours d'exécution dans un problème très étrange avec WCF. J'ai 2 projets dans une solution, chacun d'eux démarre certains services WCF auto-hébergé.

Projet 1:

myService = new ServiceHost(typeof(MyService1));

Ce qui fonctionne très bien. Cependant, lorsque je tente de lancer mon 2ème projet, qui contient:

meService = new ServiceHost(typeof(MyOtherService));

Je reçois l'exception:

FileNotFoundException
Could not load file or assembly 'System.ServiceModel' or one of its dependencies.
The system cannot find the file specified.":"System.ServiceModel

Fusion Log:

=== Pre-bind state information ===
LOG: User = removed\removed
LOG: DisplayName = System.ServiceModel
 (Partial)
LOG: Appbase = file:///C:/Work/MySln/MyProj/bin/Dev
LOG: Initial PrivatePath = NULL
Calling assembly : System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Work\MySln\MyProj\bin\Dev\MyProj.dll.temp.config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Work/MySln/MyProj/bin/Dev/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///C:/Work/MySln/MyProj/bin/Dev/System.ServiceModel/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///C:/Work/MySln/MyProj/bin/Dev/System.ServiceModel.EXE.
LOG: Attempting download of new URL file:///C:/Work/MySln/MyProj/bin/Dev/System.ServiceModel/System.ServiceModel.EXE.

La partie vraiment étrange est que dans le débogueur, au moment où je reçois cette exception, je peux aller dans « Espion » dans Visual Studio et entrez:

new MyOtherService()  // returns new instance properly
new ServiceHost()     // returns new instance properly
new ServiceHost(typeof(MyOtherService))  // throws exception, same as above.

J'ai essayé en cours d'exécution SysInternals File System Watcher pendant le débogage, mais il montre non « filenotfound » erreurs autres que devenv.exe essayer de traquer les fichiers pdb pour générer la trace de la pile.

Quelqu'un a d'autres idées de ce qu'il faut regarder?


Mise à jour # 1

J'ai vérifié le journal de fusion pour le processus, et il semble quelque chose d'étrange se produit. Il y a 2 entrées du journal pour System.ServiceModel, dos à dos:

*** Assembly Binder Log Entry  (6/1/2009 @ 10:26:48 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Program Files\TestDriven.NET 2.0\ProcessInvocation.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = removed\removed
LOG: DisplayName = System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///C:/Work/MySln/PFWebIntgTests/bin/Dev
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Documents and Settings\removed\Local Settings\Temp\TestDrivenShadowCopy\633794488082894732
LOG: AppName = domain-nunit.addin.dll
Calling assembly : PFWebIntgTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Work\MySln\PFWebIntgTests\bin\Dev\PFWebIntgTests.dll.temp.config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll.
LOG: Assembly is loaded in default load context.

Ensuite, une 2ème entrée:

*** Assembly Binder Log Entry  (6/1/2009 @ 10:26:52 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Program Files\TestDriven.NET 2.0\ProcessInvocation.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = removed\removed
LOG: DisplayName = System.ServiceModel
 (Partial)
LOG: Appbase = file:///C:/Work/MySln/PFWebIntgTests/bin/Dev
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Documents and Settings\removed\Local Settings\Temp\TestDrivenShadowCopy\633794488082894732
LOG: AppName = domain-nunit.addin.dll
Calling assembly : System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Work\MySln\PFWebIntgTests\bin\Dev\PFWebIntgTests.dll.temp.config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Work/MySln/PFWebIntgTests/bin/Dev/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///C:/Work/MySln/PFWebIntgTests/bin/Dev/System.ServiceModel/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///C:/Work/MySln/PFWebIntgTests/bin/Dev/System.ServiceModel.EXE.
LOG: Attempting download of new URL file:///C:/Work/MySln/PFWebIntgTests/bin/Dev/System.ServiceModel/System.ServiceModel.EXE.
LOG: All probing URLs attempted and failed.

Il semble donc qu'il essaie de charger System.ServiceModel deux fois, et une fois de l'application locale dir au lieu du GAC? Je suis confus ...

Était-ce utile?

La solution

Trouvé Mon problème:

Pour les deux projets (permet de les appeler MyProj1 et MyProj2) J'ai cette ligne dans le fichier .dll.config:

<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="System.ServiceModel.ServiceAuthorizationManager, System.ServiceModel" />

Proj1 fonctionne très bien, Proj2 échoue à l'exception ci-dessus. Pour une raison quelconque dans Proj2 seulement, il semble que dans mon dossier bin privé \ lorsque vous essayez de résoudre « System.ServiceModel ».

Si je change la ligne ci-dessus pour avoir le nom complet de l'assemblage:

<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="System.ServiceModel.ServiceAuthorizationManager, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Tout fonctionne à nouveau. Comment étrange ... Je ne sais pas pourquoi exactement les mêmes ouvrages de référence config pour un projet et pas une autre, mais bon ... au moins je peux retourner au travail maintenant:)

Autres conseils

Couple de questions:

  • Est-ce que vos deux projets visent au moins .NET Framework 3.0 ou supérieur?
  • Pouvez-vous nous montrer les interfaces que les deux services mettent en œuvre, et l'ébauche des classes de mise en œuvre de services eux-mêmes?

Je vais essayer de supprimer et de re-ajouter la référence dans le deuxième projet à l'Assemblée System.ServiceModel. Peut-être un autre dev a ajouté à l'aide d'un fichier local au lieu de la version GAC qui a causé des problèmes sur votre environnement local?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top