Xerratus
Happily stressed out, since 1974


 
Friday, March 24, 2006
<< Guid WTF... How NOT to create a new guid
Nova Ice's fourth win in a row at Portland Meadows >>

Problem:
Error in Visual Studio 2005
Invalid access to memory location. (Exception from HRESULT: 0x800703E6). File: web.config. Line: 86

Line 86 of the web.config file:
<add assembly="Microsoft.SqlServer.Replication, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>

Explanation:
First off, why is "Replication" being referenced by the web project in the first place?

The project I'm working on is quite complex with about 12 projects within the web solution.  Of these projects, a database project exists which utilizes replication.  While the web project does not access this project directly it does access it indirectly thru a business logic layer project which references a data access layer project which references the database project.  

With that said, when I compiled, Visual Studio automatically added <add assembly="Microsoft.SqlServer.Replication, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/> to the web.config file which in turn thru the error Invalid access to memory location. (Exception from HRESULT: 0x800703E6). File: web.config. Line: 86.  

There is no way around it.  Even when I strip out line 86, Visual Studio just adds it right back.  What's worse is that the web.config file in our web project is under source control.  So every time we compiled the web solution, Visual Studio would prompt to check out the web.config.  For a while, my team and I would just ignore the prompt and NOT check out the file (stripped of line 86 of course) and all would be fine.  But just recently, I put it back because the prompting was just too much throughout a normal work day and set out to fix this once and for all.

Solution:
Quite honestly, I don't know if this is a solution or more of a work around because I think the problem is truly a Visual Studio bug that needs to be fixed.  

With that said, here’s the work around:
First, in the database project (the project that is actually referencing the replication) right click the references in question and select "properties" and set "Copy Local" = True.  In my case, the files in question are:

Microsoft.SqlServer.ConnectionInfo
Microsoft.SqlServer.Rmo

Now compile the database project ONLY.  Once this is complete, go to the bin directory of this project and you'll see the following dlls:

Microsoft.SqlServer.BatchParser.dll
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.Replication.dll
Microsoft.SqlServer.Rmo.dll

Select and copy these.

Now, navigate to the web directory Bin folder and Paste the copied files there.

Side note: If, like me, you are using source control you can add these files to Visual Studio THEN right-click each file and select "Exclude From Project".  This will simply create a file of the exact name suffixed with the .exclude extension.  Simply, this will allow the solution to be compiled without prompting you to check out the newly added dlls.

Finally, right-click the solution in Solution Explorer and select "Clean solution" then build the solution WITH line 86 in the web.config.

Viola, it should compile without errors and the dreaded Invalid access to memory location exception should be gone.

Now, I'm not quite sure why this works but I do believe that when compiling Visual Studio is trying to access all of the referenced components but can't seem to find the Microsoft.SqlServer files.  Yes, all 4 of these files are in the GAC (Global Assembly Cache) which is why I think the error is with the Visual Studio environment.  IMHO, Visual Studio should first check to see if the referenced files are in the GAC and access them there if found.

Note: 
When "publishing" a site, be sure to strip out the Microsoft.SqlServer dll files before pushing live.  Ironically, when the project is fully compiled and published, the error no longer appears (because the .NET framework knows to look in the GAC for the files).  Because of this, my theory that the error is within Visual Studio has some weight.

Credits:
None!  This has taken my team and I quite a while to figure out.  Every week for the past few months, I've Googled this error in hopes that somebody had found a solution to no avail.  

I hope by posting my "solution" (pronounced work around), others frustrated by this error will find this entry and put an end to the elusive (Exception from HRESULT: 0x800703E6) error.