views:

2122

answers:

3

I'm running into a really strange problem with WCF. I have 2 projects in a solution, each of them starts up some self-hosted WCF services.

Project 1:

myService = new ServiceHost(typeof(MyService1));

Which runs fine. However, when I try to run my 2nd project, which contains:

meService = new ServiceHost(typeof(MyOtherService));

I get the 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.

The really odd part is that in the debugger, at the time that I get this exception, I can go into 'QuickWatch' in Visual Studio and enter:

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

I tried running SysInternals File System Watcher while debugging, but it shows no 'FileNotFound' errors other than devenv.exe trying to track down .pdb files to generate the stack trace.

Anyone have any other ideas of what to look at?


Update #1

I checked out the fusion log for the process, and it seems something strange happens. There are 2 log entries for 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.

Then a 2nd entry:

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

So it seems that it tries to load System.ServiceModel twice, and once from the local app dir instead of the GAC? I'm confused...

A: 

Couple of questions:

  • Do both of your projects target at least .NET framework 3.0 or higher?
  • can you show us the interfaces that the two services implement, and the rough outline of the service implementation classes themselves?
marc_s
Both do target .net 3.5. Strangely, in the 'broken' project, I can replace "MyOtherService" with any service interface, and they all throw the same error, which leads me to believe something in the proj itself is wrong. See my added research above for the fusion logs.
rally25rs
Could it be that you inadvertently got a copy of System.ServiceModel.dll in your apps bin directory somewhere?? I had this happen at some times that I got 2.0 32-bit copies of System.Data in my website's bin directory and couldn't build on my 64-bit machine anymore.
marc_s
Actually, the opposite is true. If I copy System.ServiceModel.dll from the GAC to my \bin path, it now runs fine. For some reason .NET is trying to resolve it from \bin. See Fusion log above (Policy not being applied to reference at this time).
rally25rs
A: 

I'd try deleting and re-adding the reference in the second project to the System.ServiceModel assembly. Perhaps another dev has added it using a local file instead of the GAC version which caused issues on your local environment?

Spence
I have tried this, it did not help.
rally25rs
A: 

Found My Problem:

For both projects (lets call them MyProj1 and MyProj2) I have this line in the .dll.config file:

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

Proj1 runs fine, Proj2 fails with the exception above. For some reason in Proj2 only, it only looks in my private \bin folder when trying to resolve "System.ServiceModel".

If I change the above line to have the full assembly name:

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

Everything works again. How odd... I have no idea why the exact same config reference works for one project and not another, but hey... at least I can get back to work now :)

rally25rs