Answered by:
c#.net code error in running the ms crm program?

Question
-
Hi,
Can any one help me to fix the following error? pleaseeee
I have the code as follows in button click, i can compile it, using CRM 4.0 version
string orgname = "Organization"; Guid leadid; //Wrap the CRM Web Service Code in a using block. using (new CrmImpersonator()) { //Create a token with the static method. ExtractCrmAuthenticationToken //The 'Context' used here is the Page.Context. CrmAuthenticationToken token = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgname); CrmService service = new CrmService(); service.CrmAuthenticationTokenValue = token; service.Credentials = CredentialCache.DefaultCredentials; //Create the lead object as usual. lead lead = new lead(); lead.subject = "Lorem"; lead.firstname = "John"; lead.lastname = "Smith"; lead.companyname = "Ipsum"; //Assign the owner as the caller ID from the token. //If you don't do this, the owner will be SYSTEM. lead.ownerid = new Owner(); lead.ownerid.type = EntityName.systemuser.ToString(); lead.ownerid.Value = token.CallerId; //Create the lead on Skype. leadid = service.Create(lead); } //Display the GUID. Response.Write(leadid.ToString());
But am getting an error at bolded line as followsOpenThreadToken failed with hr = 1008 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: OpenThreadToken failed with hr = 1008 Source Error: Line 148: Guid leadid; Line 149: //Wrap the CRM Web Service Code in a using block. Line 150: using (new CrmImpersonator()) Line 151: { Line 152: //Create a token with the static method. ExtractCrmAuthenticationToken Source File: C:\Users\Administrator\Documents\Visual Studio 2010\Projects\ContactDataEntry\ContactDataEntry\Default.aspx.cs Line: 150 Stack Trace: [InvalidOperationException: OpenThreadToken failed with hr = 1008] Microsoft.Crm.Sdk.CrmImpersonator.Impersonate() +257 Microsoft.Crm.Sdk.CrmImpersonator..ctor() +45 ContactDataEntry.Default.Button3_Click(Object sender, EventArgs e) in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\ContactDataEntry\ContactDataEntry\Default.aspx.cs:150 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Can any one help me to fix this problem/ pleaseeeeeeeeee
Srini:)Thursday, June 16, 2011 1:04 PM
Answers
-
you should get it in sdk itself (sdk\bin\64bit)??, or download latest sdk.
Mahain : My Dynamics CRM Blog- Marked as answer by SriniTheLearner Friday, June 17, 2011 5:55 AM
Friday, June 17, 2011 4:46 AMModerator
All replies
-
Hello Srini,
Pleaseeeeeee stop write in every post pleaseeeeeeee.
Regarding you error - are you trying to run your code from Visual Studio? if yes - this would not work. You should publish your application under IIS and try to run it from CRM context.
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)
- Proposed as answer by Andrii ButenkoMVP, Moderator Thursday, June 16, 2011 2:28 PM
Thursday, June 16, 2011 1:09 PMModerator -
Hi Andriy,
may i know where i have posted this same issue.
Srini:)Thursday, June 16, 2011 1:25 PM -
Hi Andriy,
may i know where i have posted this same issue.
Srini:)Everywhere pleaseeeeeeee.
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)
Thursday, June 16, 2011 1:30 PMModerator -
Hello Andriy,
All posts are not same!! right?
To the best of my knowledge one can post n number of posts regarding different issues, it may not be a problem, if not plz suggest me.
Thanks,
Srini
Srini:)Thursday, June 16, 2011 1:43 PM -
I didn't meant that posts are the same. I meant usage of "pleaseeeeee" instead of usual "please" because it looks silly.
Anyway - have you solved you issue with the code?
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)
Thursday, June 16, 2011 2:28 PMModerator -
Hi Andriy,
OK, I will follow your suggestion by up coming messages.
Sorry i misunderstood.
Regarding my error: its not resolved. Problem is,
I have developed my application in VS2010 targetframeword as 4.0.
If i published it, it show the following error.
"Server Error in '/' Application. Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive. Source Error: Line 6: <configuration> Line 7: <system.web> Line 8: <compilation debug="true" targetFramework="4.0"> Line 9: </compilation> Line 10: <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web> Source File: C:\inetpub\wwwroot\MSCRM\web.config Line: 8"
If i changed framework to 3.5 in properties, then i got build errors near 25000.
Error 1 The type or namespace name 'Xrm' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) D:\srini\VS2010\ContactDataEntry\ContactDataEntry\Default.aspx.cs 7 17 ContactDataEntryERROR:
like wise i got 25000 errors.What i need to do? can you suggest me please
Srini:)Thursday, June 16, 2011 3:18 PM -
make sure you are setting Asp.net v4.0 application in your application.
Mahain : My Dynamics CRM BlogThursday, June 16, 2011 3:24 PMModerator -
Hi Mahender,
Your correct, i kept it in 3.5. If i changed it to 4.0 i got the following error,
"
Could not load file or assembly 'microsoft.crm.sdk' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'microsoft.crm.sdk' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'microsoft.crm.sdk' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
"Can you please help me to fix this problem? please
Srini:)Thursday, June 16, 2011 3:37 PM -
Hi Vikram,
even no change, same error vikram.
Srini:)Thursday, June 16, 2011 3:47 PM -
you need to make sure ‘Microsoft.Crm.WebServices.dll’ is in GAC, if it’s not there please follow below steps to Place it in GAC.
a. Go to “C:\Program Files\Microsoft Dynamics CRM\Setup” folder.
b. Select “Microsoft.crm.Webservice.dll” and drag it under “C:\Windows\assembly” folder
Also if you are using 64 bit system try to add 64 crm sdk instead of 32 bit
Mahain : My Dynamics CRM Blog
Thursday, June 16, 2011 3:52 PMModerator -
Hi Srini,
if you are using CRM 4.0 then .net Version should be 3.5 .
Thursday, June 16, 2011 3:53 PM -
Hi Mahender,
i have dragged the dll under c:\windows\assembly folder but its not showing the new Microsoft.crm.webservices.dll in GAC folder.
then i have restarted the iis even am facing same error.
Srini:)Thursday, June 16, 2011 4:03 PM -
Also if you are using 64 bit system then try to add 64 crm sdk instead of 32 bit
Mahain : My Dynamics CRM Blog- Proposed as answer by Jim Glass Jr Thursday, June 16, 2011 5:58 PM
Thursday, June 16, 2011 4:10 PMModerator -
Mahender,
Where can i get 64bit crm sdk. I am using 64-bit system. I have searched for it, but didn't get.
Can you send me the link plz.
Srini:)Friday, June 17, 2011 3:57 AM -
you should get it in sdk itself (sdk\bin\64bit)??, or download latest sdk.
Mahain : My Dynamics CRM Blog- Marked as answer by SriniTheLearner Friday, June 17, 2011 5:55 AM
Friday, June 17, 2011 4:46 AMModerator -
Mahender,
Finally i can run the crm code in iis. Thanks A lot.
but i have an another code issue in crm, can you have a look at this please.
I have the code as follows in button click, i can compile it, using CRM 4.0 version
" string orgname = "Organization";Guid leadid;
//Wrap the CRM Web Service Code in a using block. using (new CrmImpersonator()) { //Create a token with the static method. ExtractCrmAuthenticationToken //The 'Context' used here is the Page.Context. CrmAuthenticationToken token = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, orgname); CrmService service = new CrmService(); service.CrmAuthenticationTokenValue = token; service.Credentials = CredentialCache.DefaultCredentials; //Create the lead object as usual. lead lead = new lead(); lead.subject = "Lorem"; lead.firstname = "John"; lead.lastname = "Smith"; lead.companyname = "Ipsum"; //Assign the owner as the caller ID from the token. //If you don't do this, the owner will be SYSTEM. lead.ownerid = new Owner(); lead.ownerid.type = EntityName.systemuser.ToString(); lead.ownerid.Value = token.CallerId; //Create the lead on Skype. leadid = service.Create(lead); } //Display the GUID. Response.Write(leadid.ToString());
But am getting an error at bolded line as follows
"OpenThreadToken failed with hr = 1008 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: OpenThreadToken failed with hr = 1008 Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [InvalidOperationException: OpenThreadToken failed with hr = 1008] Microsoft.Crm.Sdk.CrmImpersonator.Impersonate() +278 MSCRMWeb.Default.Button1_Click(Object sender, EventArgs e) in C:\Users\Administrator\documents\visual studio 2010\Projects\MSCRMWeb\MSCRMWeb\Default.aspx.cs:25 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691"
Can any one help me to fix this problem? please
Srini:)Friday, June 17, 2011 5:55 AM