The path is too long after being fully qualified. Make sure the full path is less than 260 characters and the directory name is less than 248 characters.
I recently ran into this exception using IIS to host WCF services. This exception can be a little confusing at first if you don’t know the way that IIS works. The error message is pretty simple: an assembly that our IIS application is trying to load is too long, exceeding either the 248 character directory limit or the 260 character full path limit imposed by Windows. What if you check the longest path in your bin folder and it’s well under these limits?
I do not recommend using IIS to host WCF services, unless you’re only hosting simple REST services or HTTP SOAP services. IIS is too full of hacks to be taken seriously as a WCF host in the enterprise, even with AppFabric extensions. Either self-host, or use a WCF Platform like SOAcollective that includes a host. Word has it that Microsoft knows full well that IIS is a hack and are working on an AppFabric host.
Let’s say that you have a virtual directory in IIS under your Default Web Site called Services in the folder path C:\IIS\Default\Services. Under that virtual directory, you have a virtual directory called Finance (to logically and physically groups services). Under that directory is a virtual application for Accounting that houses the different Accounting services. So in our example, the setup looks like this:
So far so good. In this folder we also have a bin folder with our assemblies. Let’s say that the the longest assembly name is CompanyName.Finance.Accounting.ResourceAccess.Engines.Invoicing.dll. So our longest path would be:
107 characters in the directory name, 175 characters total
These names are certainly verbose, but we’re well under the limits, so no problem right? Wrong.
The way IIS works is that it actually copies your top level virtual directory folder to a temporary folder under C:\Windows\Microsoft.NET\[bit version]\[.net version]\Temporary ASP.NET Files\. That’s not great, but the problem gets worse. IIS also adds several folders within your original path in order to finally make it to the final assembly. Your end result might look something like this:
C:\WindowsMicrosoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\services_finance_accounting_business_companyname_finance_accounting_managers_servicehost\c9de03fe\39f7e24b\assembly\dl3\0fca731c\e3b3c2cf_d84acc01\CompanyName.Finance.Accounting.ResourceAccess.Engines.Invoicing.dll
218 characters in the directory name, 286 total
This fix of course is simple: shorten your names to work within the quirks/limitations of IIS and Windows.