If you ever get the error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.", take a look at the rest of this post, it might save you a lot of time... I got it when writing a console application for SharePoint, but I think it might occur with other sorts of applications too.
I had been looking for a solution for many days and had seen lots of possible causes online, but none of them applied to my situation. Today, I noticed for the first time that Visual Studio gave me a warning when building. I hadn't noticed this before because there weren't any errors, so it just said "build succeeded", so I thought everything in my application was fine and it must have been something about the setup of the test server. Well, I clearly was wrong... Here's what the warning said:
Found conflicts between different versions of the same dependent assembly.
When double clicking this warning, Visual Studio asks you if you want it to fix the errors by adding binding redirect records in the app.config file. If you choose "yes", then Visual Studio adds some lines to the app.config file. Here's what it added for me:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SharePoint.Library" publicKeyToken="71E9BCE111E9429C" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.SharePoint" publicKeyToken="71E9BCE111E9429C" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.SharePoint.Security" publicKeyToken="71E9BCE111E9429C" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.SharePoint.Dsp" publicKeyToken="71E9BCE111E9429C" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Now just rebuild your project and try running it again... Everything should be working fine now!
Subscribe to:
Post Comments (Atom)
1 comment:
I will not approve on it. I think warm-hearted post. Specially the designation attracted me to study the whole story.
Post a Comment