Pergunta

Eu estou correndo em um problema realmente estranho com o WCF. Eu tenho 2 projetos em uma solução, cada um deles começa-se alguns serviços WCF auto-hospedados.

Projeto 1:

myService = new ServiceHost(typeof(MyService1));

O que funciona muito bem. No entanto, quando tento executar o meu segundo projecto, que contém:

meService = new ServiceHost(typeof(MyOtherService));

Eu recebo a exceção:

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

Fusão 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.

A parte realmente estranho é que no depurador, no momento em que eu recebo esta exceção, eu posso entrar em 'QuickWatch' em Visual Studio e digite:

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

Eu tentei correr SysInternals Arquivo Monitorização do Sistema durante a depuração, mas não mostra que não devenv.exe tentando erros 'FileNotFound' para rastrear .pdb para gerar o rastreamento de pilha.

Alguém tem alguma outra idéia do que para olhar?


Atualização nº 1

Eu verifiquei o log de fusão para o processo, e parece algo estranho acontece. Existem 2 entradas de log para System.ServiceModel, volta para trás:

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

Em seguida, uma segunda entrada:

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

Assim, parece que ele tenta carregar System.ServiceModel duas vezes, e uma vez a partir da dir aplicativo local em vez do GAC? Estou confuso ...

Foi útil?

Solução

Encontrado o meu problema:

Para ambos os projetos (vamos chamá-los MyProj1 e MyProj2) Eu tenho esta linha no arquivo .dll.config:

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

Proj1 funciona muito bem, Proj2 falha com a exceção acima. Por alguma razão em Proj2 única, que só olha na minha pasta privada \ bin ao tentar resolver "System.ServiceModel".

Se eu mudar a linha acima para ter o nome montagem completa:

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

Tudo funciona novamente. Que estranho ... Eu não tenho idéia por que exatamente as mesmas obras de referência de configuração para um projeto e não outro, mas hey ... pelo menos eu posso voltar ao trabalho agora:)

Outras dicas

par de perguntas:

  • Do ambos os projectos visam, pelo menos .NET framework 3.0 ou superior?
  • você pode nos mostrar as interfaces que os dois serviços implementar, eo esboço das classes de implementação serviço de si mesmos?

Eu tentaria apagar e re-adicionar a referência no segundo projeto para o System.ServiceModel montagem. Talvez outro dev adicionou-lo usando um arquivo local em vez da versão GAC que causou problemas em seu ambiente local?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top