WCF genera un'eccezione FileNotFound per “System.ServiceModel” durante la creazione ServiceHost

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

Domanda

Sono in esecuzione in un davvero strano problema con WCF. Ho 2 progetti in una soluzione, ciascuno di loro si avvia alcuni servizi WCF self-hosted.

Progetto 1:

myService = new ServiceHost(typeof(MyService1));

Il che funziona bene. Tuttavia, quando si tenta di eseguire il mio secondo progetto, che contiene:

meService = new ServiceHost(typeof(MyOtherService));

Ho l'eccezione:

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 parte veramente strana è che nel debugger, nel momento in cui ottengo questa eccezione, posso andare in 'Controllo immediato' in Visual Studio e digitare:

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

Ho provato a fare funzionare SysInternals File System Watcher durante il debug, ma mostra gli errori no 'FileNotFound' diverse da devenv.exe cercando di rintracciare file PDB per generare la traccia dello stack.

Qualcuno ha altre idee su cosa guardare?


Aggiornamento # 1

Ho controllato il registro di fusione per il processo, e mi sembra qualcosa di strano accade. Ci sono 2 voci di registro per System.ServiceModel, back to back:

*** 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.

Poi una seconda voce:

*** 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.

Così sembra che si cerca di caricare System.ServiceModel due volte, e una volta dalla app dir locale anziché il GAC? Sono confuso ...

È stato utile?

Soluzione

Trovato mio problema:

Per entrambi i progetti (permette loro di MyProj1 e MyProj2 chiamare) ho questa riga nel file .dll.config:

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

Proj1 funziona bene, Proj2 esito negativo con l'eccezione di cui sopra. Per qualche motivo in Proj2 solo, sembra solo nella mia cartella privata \ bin quando si cerca di risolvere "System.ServiceModel".

Se cambio la linea di cui sopra per avere il nome di montaggio completo:

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

Tutto funziona di nuovo. Che strano ... Non ho idea del perché le stesse identiche opere di riferimento di configurazione per un progetto e non un altro, ma hey ... almeno posso tornare a lavorare adesso:)

Altri suggerimenti

Un paio di domande:

  • fare entrambe le cose dei vostri progetti bersaglio almeno NET Framework 3.0 o superiore?
  • ci può mostrare le interfacce che i due servizi implementano, e l'abbozzo delle classi di implementazione dei servizi stessi?

Mi piacerebbe provare la cancellazione e ri-aggiungendo il riferimento al secondo progetto al gruppo System.ServiceModel. Forse un altro dev ha aggiunto utilizzando un file locale invece della versione GAC che ha causato problemi sul vostro ambiente locale?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top