web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Getting System.Security.SecurityException while sending file using JSON string with HTTPWEBREQUEST on record create

(0) ShareShare
ReportReport
Posted on by 10

Hello, 

I have a plugin ( CRM 365 on premise) that will pass certain data along with a file  using JSON String (or JSON object) with HttpWebRequest, this plugin works fine with file that is smaller than 26 kb, but will throw  System.Security.SecurityException without even execute the plugin code when file is around 26 kb or bigger. 

Any advice will be very much appreciated. 

ERROR: 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Security.SecurityException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #6DF5358FDetail:
<OrganizationServiceFault xmlns:i="">www.w3.org/.../XMLSchema-instance" xmlns="">schemas.microsoft.com/.../Contracts">
<ActivityId>bce3c532-ae6e-46a2-ab7c-9b069a56a312</ActivityId>
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="">schemas.datacontract.org/.../System.Collections.Generic" />
<Message>System.Security.SecurityException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #6DF5358F</Message>
<Timestamp>2019-10-31T19:15:46.7828725Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource>PluginExecution</ExceptionSource>
<InnerFault i:nil="true" />
<OriginalException>System.Security.SecurityException
at System.ComponentModel.Win32Exception.GetObjectData(SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String&amp; typeName, String&amp; assemName, String[]&amp; fieldNames, Object[]&amp; fieldValues)

CODE: 

var request = requestParams.ContainsKey("entityid")
? (HttpWebRequest)WebRequest.Create($"{configurations.ServiceUrl}/{functionName}")
: (HttpWebRequest)WebRequest.Create($"{configurations.ServiceUrl}/{functionName}?{requestData}");

request.ContentType = "application/json";
request.AllowAutoRedirect = true;
request.SendChunked = true;
request.TransferEncoding = "utf-8";
request.KeepAlive = false;
request.Timeout = Timeout.Infinite;
request.ProtocolVersion = HttpVersion.Version11;
request.AllowWriteStreamBuffering = true;


String recordID = requestParams["RECORDID"].ToString().Replace("\"", "\\\"");

String DocumentFileName = requestParams["DocumentFileName"].ToString().Replace("\"", "\\\"");

var objAttachedDocument = entity.Attributes[requestParams["attributename"]].ToString().Replace("\"", "\\\""); ;

var valData = "{ \"RECORDID\": " + recordID + ", \"DocumentFileName\": \"" + DocumentFileName + "\", \"objAttachedDocument\": \"" + objAttachedDocument + "\"}";
localContext.Trace(valData);

using (StreamWriter sw = new StreamWriter(request.GetRequestStream()))
{
sw.Write(valData);
}

var response = (HttpWebResponse)request.GetResponse()

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans