System.IO.FileNotFoundException when creating SPSite objects using the SharePoint object model


This is one of the interesting errors that we encountered recently. A console application was developed for content migration from a file share to SharePoint with an Excel file for mapping the files to specific content types. The application was run on our test environment and everything seemed to work fine. Of course we wanted to run this over the weekend. Time for easy deployment right since it is all tested and ready right? Wrong! When deploying to the server we came across this error

“Provider not registered in this environment” . After a bit of googling we realized the issue. Our test environment was running a 32 bit SharePoint installation, whereas the production version was 64 bit. Since we were using Jet drivers to connect to the Excel spreadsheet, we had to retool our application or target a specific architecture(since 32 bit drivers are available on the server). We chose the second option. We set the target platform to x86 and deployed it on production.

Update: Here is the forum post with the link to the solution. Scroll down to the 3rd comment with a link to the vbtips site  http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=125207&SiteID=1

Now we were seeing the dreaded System.IO.FileNotFoundException when creating SPSite objects in our code.

Apparently setting the target architecture to x86 and running the code on a x64 SharePoint installation, throws the FileNotFoundException. We changed the target architecture back to the default setting and had to retool the code to read the mappings using an Xml export.

6 Responses to System.IO.FileNotFoundException when creating SPSite objects using the SharePoint object model

  1. Mitali says:

    Hey! I was facing a similar problem….
    There seemed to be no solution….everything was right still was getting the issue….finally read your blog and got the solution…..
    Thanks a lot….this blog helped me solve the issue…..

  2. Deepak says:

    Hi, I had the same issue today. Using the XML was a good one, also wanted to let someone who drop by to know now we have the open source ExcelDataReader at codeplex, this worked from me in bothe x86 and x64 bit servers.

    —–
    Deepak

  3. Constantin says:

    good one! I always keep forgetting that I should compile my app to “Any CPU”.
    thanks for reminding.

  4. Pingback: System.IO.FileNotFoundException on "SPSite = new SPSite(url/IP)" « Ammar's IT Blog

  5. Pingback: new SPSite – FileNotFoundException « Thornton Technical

  6. Rajan says:

    thanks….nice post

Leave a comment