Error: “sgen.exe” exited with code 1

While building a project or solution, if  you get the error like: “sgen.exe” exited with code 1, then the most probable reason is because you have a different version of the same project’s DLL in the GAC.

Solution:

  1. Open the GAC (C:\Windows\Assembly), find the DLL corresponding to your project.
  2. Right click on it and select uninstall

Now re-build your project and the problem must be gone.

InfoPath Forms Code Error: Schema validation found non-data type errors

As per Microsoft InfoPath blog this error occurs when we are trying to set a nodes element value and the node has an xsi:null attribute. So, before setting any value check if the node has the xsi:nil attribute and if so delete that attribute. Belowcode snippe is from the same blog which can be used as a generic method before setting any value.

public void DeleteNil(XPathNavigator node)

{

if (node.MoveToAttribute(“nil”, http://www.w3.org/2001/XMLSchema-instance”))

node.DeleteSelf();

}

I had similar problem while appending rows to a repeating table using the XmlWriter in the code behind for an InfoPath Form. Unfortunately, the code snippet didn’t solved my problem. Examining the xml contained in the node using the innerxml property, I didn’t find any xsi:nil anywhere. However after struggling for 2 hours I was able to find the solution and this problem is specific to the repeating table.
Solution:
The order in which we are appending the values in the code should be in the same order as is in the form design’s data source.

Below is a more detailed explanation. The repeating table in the InfoPath Form design was as follows:

-commentTable
–commentRow
—userID
—commentText
—occurrenceTime

commentTable being the root of the repeating table control. commentRow is the repeating table. The columns within a row are and its order is as show above: userID, commentText, occurrenceTime.

In the code behind of the form, I have my code as follows:


myRoot = MainDataSource.CreateNavigator();
node = myRoot.SelectSingleNode("/my:Main/my:commentTable", NamespaceManager);
DeleteNil(node);
using(XmlWriter writer = node.AppendChild())
{

writer.WriteStartElement("commentRow", myNamespace);
writer.WriteElementString("userID", myNamespace, "user id");
writer.WriteElementString("occurrenceTime", myNamespace, "12/20/08 10:00:00");
writer.WriteElementString("commentText", myNamespace, "test comment");
writer.WriteEndElement();
writer.Close();

}

Everything looks perfect! Err… No!, the order in which I am writing the xml into the node is not in the correct sequence as it is in the InfoPath form design. In my code i am trying to write the ‘occurrenceTime’ before the ‘commentText’ which is not as per the design. So swapping it solved my problem. Though it is silly its important for the xml schema and that is the reason the schema validation fails.

How To: Access Contact Selector control data in infopath forms code behind and Microsoft.Office.Workflow.Utility not found problem

To access the contact selector we need to use the Contact class for which we need to add this line into our code file:

using Microsoft.Office.Workflow.Utility;

The next question is where does this library sit and how to add reference to it. Well, just as any developer does I too opened up the Add Reference window but I couldn’t find the library I am looking for i.e Microsoft.Office.Workflow DLL. I couldn’t find neither under the .Net tab nor under the Components tab.

You can find the required DLL at: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\microsoft.office.workflow.tasks.dll

Later, I realized that you can find it under the .NET tab with the component name: “Microsoft Office Server DLC Component”.

Add Reference

I would be glad if this post is helpful to someone or other.

As per the title of this post, to learn how to access the contact selector control’s data programmatically in the code behind please read the below posts from msdn.

Link1 and Link2

Using stsadm to deploy, upgrade, update InfoPath Forms Templates with Managed code behind

This post talks about using stsadm and batch scripts to deploy InfoPath form with code behind which usually is called as InfoPath forms with managed code or the InfoPath forms managed templates.

The problem: If it’s just a couple of InfoPath forms with simple code behind we can deploy the form using the InfoPath Forms Client application itself. As laid out neatly here. To summarize, it involves the following steps:

  1. Publish to a network location
  2. Verify its browser compatible while uploading to InfoPath managed templates in Central Admin.
  3. Upload to InfoPath managed templates found in Central Administration
  4. Wait for the status to upload complete.
  5. SharePoint admin should activate it for a particular site where the developer want to use it.
  6. Wait for the activation to complete.

Imagine doing all this every time you make change to the code behind of the form or change the user interface. The worst part is waiting for the status to get completed as SharePoint does those kind of jobs based on the timer job service. To run these tasks forcefully the stsadm’s execsrvcjobs command operation comes handy.

Below is the script to install a new infopath form template and activate for a particular site collection:
::Publish the form to a location lets say it is published at C:\InfoPathForms\Publish\sample.xsn
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
::uncomment the below three lines if you want to uninstall and re-install the infopath form template
::stsadm.exe -o DeActivateFormTemplate -url http://demosite -filename ::C:\InfoPathForms\Publish\sample.xsn
::stsadm.exe -o RemoveFormTemplate C:\InfoPathForms\Publish\sample.xsn
::stsadm.exe -o execadmsvcjobs
stsadm.exe -o verifyformtemplate -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o UploadFormTemplate -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o execadmsvcjobs
stsadm.exe -o ActivateFormTemplate -url http://demosite -filename C:\InfoPathForms\Publish\sample.xsn

Below is the script to upgrade or update the existing infopath form template for a site collection:
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
stsadm.exe -o DeActivateFormTemplate -url http://demosite -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o verifyformtemplate -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o UpgradeFormTemplate -filename C:\InfoPathForms\Publish\sample.xsn
stsadm.exe -o execadmsvcjobs
stsadm.exe -o ActivateFormTemplate -url http://demosite -filename C:\InfoPathForms\Publish\sample.xsn

UPDATE: If you just changed the code behind of the form and want to deploy it there is even better and quicker way to do it. When the form is deployed using the above stsadm scripts what it does is, it depoys the form as a content type feature and the folder name is some what like FT- which is found under C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\
Under this you will find folder liek solution.xsn.1.0.0.210.1.0.0.210. Find the latest one and drop the updated DLL’s in there and then reset the IIS or recycle the app pool for the site collection. That is it!!

PS: I got the initial help of preparing the batch script from here.

Cannot open log for source . You may not have write access

If you get the error some thing like (while writing to the event log):

Cannot open log for source {0}. You may not have write access

As quick solution is to increase or raise the user permissions temporarily to write the event log and then revert back the elevated permissions.

Below is the code:

System.Security.Principal.WindowsImpersonationContext wic = System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
--your Code to write to event log or any to do something which needs elevated permission--
wic.Undo();

How to show the forms library item data to which workflow is attached in the infopath based task form

I have an infopath forms library list in my SharePoint site. (Forms library is basically a document library whose content type is of InfoPath forms type or xml document type) This list holds the request forms which end users submit using the browser based infopath form.

I have my custom workflow developed in VS 2005 attached to the abvoe forms/document library. My custom workflow has couple of task forms developed using InfoPath again, which the reviewer and approver uses to approve/re-assign/reject the request form.

My question is how to show the whole request forms data preferably with the same design and structure within the task forms. So here I am trying to show the request form which is a infopath form in a task form which is again another infopath form. May be atleast a readonly view of the request form will also suffice.

This helps the reviewer and the approver to see the client request within the task form and take the decision to approver or reject or re-assign.

I hope I am clear with my question. Please let me know your comments and a direction to go around to solve this. Thanks a lot guys :)

InfoPath cannot connect to a data source when viewed in browser – Cross Domain Issues – Universal Data Connection

InfoPath cannot run the specified query.

InfoPath cannot connect to the data source.

Access is denied.

One of the big issues with InfoPath Forms is its error reporting. It could sometimes piss you off. It says there is a problem that is it! We have to spend lot of time clicking and clicking and clicking buttons all over trying to find where is the problem. May be that is how these tools should work…

Steps to go with when you get the above error:

  1. The above error seems to be quite often and it hints that there is some problem with the ‘Data Source/Connection’. If the form is showing the error while loading i.e form never loads but shows a message to ‘continue or start over’, then there is some problem with the data source which is set up to ‘Automatically retrieve data when form is opened’.
  2. If the above is the situation then open up the Data Sources window (Tools – Data Connections) and make sure that the data connection is set up properly and the data source is in place, working and serves requests.
  3. If the above error is shown when user does some action like clicking on button, then check the Rules in the properties of that control (button) and check for those data sources/connections.
  4. If the form works fine when previewed as an application but throws the above error after publishing to SharePoint site or when viewed as a browser form, then most probably the problem will be with the cross domain issue. If the InfoPath is trying to query or submitting to a web service (could be any other data source) and that web service is hosted as http://xyz.com/service.asmx and the sharepoint site is hosted as http://abc.com then thats called a cross domain issue. The infopath form is trying to talk to a service which is hosted in a different domain and it can’t trust it. This can be solved by giving full trust to the form(Tools – Form Options – Security and Trust) but its not the right way to go and your SharePoint admin might restrict that. The only way to go is setting the security and trust to ‘Domain’ and converting the existing data connections or just the cross domain connections to Universal Data Connection (UDC) format. Its very simple to do and gets rid of any cross domain issues. To create UDC connections read this article. For those who have no patience to read the article, below are the quick steps involved:
    1. If Universal data connection document library doesn’t exist in the SharePoint site then create one or request your admin to create one and give you proper rights for you. (Go to ‘View all site content’ – Create – Universal Data Connection Library)
    2. Open up the InfoPath forms Data Connections window, select the cross domain data source connect and then click the ‘Convert’ button and follow the wizar. You need to provide the above created UDC library along with a name for the file for example: http://abc.com/udclibraryname/sampleudc.udcx
    3. Now that is not enough, either you or your admin should approve the sampleudc.udcx document created in the UDC library.
    4. Re-publish the InfoPath form to SharePoint and test it.
  5. In central administration, under InfoPath Forms Services configuration, there is a checkbox to allow cross-domain issues. I am not sure if this is done then above UDC is still required or not. I will update as I learn about it.

More links worth to read:

InfoPath Forms 2007: Web Service – Change URL – Fix URL – URL Problem

Today I had this weird problem: I downloaded a custom workflow sample which has an InfoPath form. The infopath form has a data source which retrieves using a web service. Since the form was already designed the web service URL used to set up the ‘Retrieve data source’ was some what like : http://localhost/_vti_bin/ExternalSystemService.asmx?WSDL

Even when I tried to modify the data source by giving my own web service url(http://myspsite:port), it still shows that web service url is pointed to the localhost. Because there is no web service running on my localhost website the form fails in preview mode and of course fails in SharePoint once it is published to a forms library. See the screen shot below:

InfoPath data source web service

Doing a quick search, I found this KB article which is related to InfoPath 2003. According to it the way to change the web service url is to extract the infopath forms files and edit the manifest xml file. Going about in this direction, for InfoPath forms 2007, just save the InfoPath forms as source files using ‘File > Save as Source Files’ menu. Then edit the manifest.xsf file in notepad, search for localhost and replace it with your own service url:port. Then right click the same file and select Design and you will the data source now shows the correct web service url.

InfoPath data source web service fixed

Follow

Get every new post delivered to your Inbox.