Error InfoPath has encountered an error. The operation failed.

Fai Developer 21 Reputation points
2020-12-09T13:17:20.3+00:00

I am using InfoPath Designer 2013 along with Microsoft Visual Studio Professional 2012 in SharePoint 2013

I am trying to migrate a InfoPath form code from SharePoint 2010 to SharePoint 2013. In SharePoint 2010 we were using InfoPath designer 2007.

But below error is generic error I get in my development environment. I will explain it by creating an empty code project from start.

I am working with InfoPath solution with Full trust with managed code including code from SharePoint object model on Microsoft Windows Server 2012 R2 Standard server machine.

I create a new clean InfoPath solution and click on Code Editor and it opens then code by "Code Editor" button.

I build the solution and it works fine.

Next stage is to add SharePoint reference dll from C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.dll and build the solution and it builds fine wihout any error.

The I just add a small piece of SharePoint code SPContext.Current.Web.Url

and build it but then I get error and warning as shown below.


Warning 2 The primary reference "Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly"System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.SharePoint,Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets 1605 5


Error: Error 1 The type or namespace name 'SharePoint' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) C:\Users\myusername\AppData\Local\Temp\5\Vsta\InfoPath\VstaJPquu1x5GkOwBi01lDqNsA\VstahqHPCqWNWUi91YBMd0kcGg\FormCode.cs 5 17


Then I believe above error may be because of wrong Target Framework in Project settings.

I go into Project settings and it is Target Framwork = .NET Framwork 4 mentioned there

Then I modified "Target Framwork" to ".NET Framwork 4.5". Build it and it build the solution successfully without any warning/error.

But then when i try to publish it I get "Error InfoPath has encountered an error. The operation failed." in a dialogue message.

Now the InfoPath template is no more save-able. Every time I try to save it it gives me error. "InfoPath cannot save the following form. File cannot be accessed"

Then I closed InfoPath designer and re-opened it then again clicked on the Code Editor and it opens then code Project. I checked Target Framwork that was again setted back to .NET Framwork 4 and if i try to build code then it failsand giving med same error and warning as mentioned above

Anyone here has experienced such problem?

Thanks in advance

fai_developer

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,346 questions
{count} votes

Accepted answer
  1. Elsie Lu_MSFT 9,796 Reputation points
    2020-12-10T08:00:10.017+00:00

    Hi @Fai Developer ,
    According to your description, I found some solutions:

    1.Specific version signifies that Visual Studio will only build if it has access to the specific version of the referenced assembly.
    This kind of error/check is enforced mostly when we implement .net assemblies targeting different versions of .net framework than the target Framework of the current project.

    You could try to use this solution:
    46649-5.jpg
    Please refer to this blog for more information:
    https://realmpkdotnet.wordpress.com/2015/11/04/the-primary-reference-could-not-be-resolved-because-it-has-an-indirect-dependency-on-the-framework-assembly/

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

    2.Try to upgrade the InfoPath solution for 2010 may not be very valuable. So you could try to rebuild an empty solution for .net 4.5 version.
    3.I would suggest you try to make a custom web part of server object model instead of InfoPath, because InfoPath is no longer in the life cycle as below:
    46758-4.jpg


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.