Problem with TemporaryKey.pfx I don’t have the password

[Origin]: http://stackoverflow.com/questions/3842481/problem-with-temporarykey-pfx-i-dont-have-the-password

A client of mine has a problem. He had a Microsoft CRM developper and he left. Now the project remains uncomplete. I’ve downloaded the source code of the custom applications and I’m not trying to continue the development. I’ve tried the ClickOne deployment and it pops me with a password input box related to the myapp_TemporaryKey.pfx. I’ve tried to install on a computer on the network and launch in debugging mode, and I get the same problem, it says :

“Cannot import the following key file: . The key file may be password protected. To correct this, try to import the certificate again or import the certificate manually into the current user’s personal certificate store.”

And a second error is: “Importing key file “myapp_TemporaryKey.pfx” was canceled

Do you know what can be done to fix that? I have the .PFX file, but not the password.

shareedit

I Went to project properties –> Signing tab–> then signed my app using the certificate. In my case. The build was successful

shareedit
Advertisements

JSON and CRM Sandbox Plugins

[Originally posted by]: http://www.crmanswers.net/2015/02/json-and-crm-sandbox-plugins.html

JSON and CRM Sandbox Plugins

Today I was working on a plugin and one of the requirements was a call to a web service passing some POST parameters, nothing complicated but I want to share part of the process.

Normally I register my plugins always inside Sandbox, the main reason is that I don’t need to care where the plugin is executed (in this specific case the development is OnPremise but the production is Online), the second reason is that my user is often forgotten to be added as Deployment Administrator 🙂

One of the parameter was a JSON Object passed as string, practically I needed to do the C# equivalent of a JSON.stringify in order to pass a complex structure. An example can be the following Course object (JavaScript):

var Course = new Object();
Course.Name = "CRM Development 1";
Course.Teacher = "Prof. John Smith";

Course.Students = new Array();
Course.Students[0] = new Object();
Course.Students[0].ID = "001";
Course.Students[0].Name = "Walter Davis";

Course.Students[1] = new Object();
Course.Students[1].ID = "002";
Course.Students[1].Name = "Mark Harris";

var parameter1 = JSON.stringify(Course);

Because I was inside a Sandbox plugin I couldn’t use the Newtonsoft.Json library and I didn’t want to waste time trying to merge it inside my plugin.

The .NET framework provides different methods to create a JSON output, in particularJavaScriptSerializer (from System.Web.Script.Serialization namespace) andDataContractJsonSerializer (from System.Runtime.Serialization.Json namespace).

JavaScriptSerializer is very easy to use (it has a Serialize method returning a string) but doesn’t work inside Sandbox, so I used DataContractJsonSerializer:

var Course = new Object();
Course.Name = "CRM Development 1";
Course.Teacher = "Prof. John Smith";

Course.Students = new Array();
Course.Students[0] = new Object();
Course.Students[0].ID = "001";
Course.Students[0].Name = "Walter Davis";

Course.Students[1] = new Object();
Course.Students[1].ID = "002";
Course.Students[1].Name = "Mark Harris";

var parameter1 = JSON.stringify(Course);

A bit longer code but compatible with Sandbox and CRM Online.

Serializing/Deserializing JSON in Dynamics CRM 2013/2015 Plugin

Taken from: http://stackoverflow.com/questions/33010055/serializing-deserializing-json-in-dynamics-crm-2013-2015-plugin

I am developing a plugin for Dynamics 2015. The plugin requires some setup information which I thought would be a good idea to use a json object in the unsecure configuration. Also, there’s an external system which is writing some json into a field in the entity that this plugin responds to which I need to extract information from.

I have tried to use JavascriptSerializer object to deserialize the json but I get a System.MethodAccessException, upon doing some research, I have found out that I can’t use the JavascriptSerializer in sandbox mode.

I don’t want to have to ILMerge Json.Net into my assembly, so is there any other way I can serialize/deserialize json in my plugin code?

shareedit

So here’s how I solved this one

Given

string wsData = string.Empty;
plItem.GetType() == typeof(CategoryInfo);

and

[DataContract]
public class CategoryInfo 
{
    [DataMember]
    public string AllPropertiesToSerialize{ get; set; }
} 

then

using (var ms = new MemoryStream())
{
     var js = new DataContractJsonSerializer(typeof(CategoryInfo));
     js.WriteObject(ms, plItem);
     ms.Position = 0;
     var sr = new StreamReader(ms);
     wsData = sr.ReadToEnd();
} 

Thanks to @dbc and @Guido Preite for the pointers

shareedit

JSON and CRM Sandbox Plugins

[Originally Posted By]: https://community.dynamics.com/crm/b/crmanswers/archive/2015/02/09/json-and-crm-sandbox-plugins

Today I was working on a plugin and one of the requirements was a call to a web service passing some POST parameters, nothing complicated but I want to share part of the process.

Normally I register my plugins always inside Sandbox, the main reason is that I don’t need to care where the plugin is executed (in this specific case the development is OnPremise but the production is Online), the second reason is that my user is often forgotten to be added as Deployment Administrator 🙂

One of the parameter was a JSON Object passed as string, practically I needed to do the C# equivalent of aJSON.stringify in order to pass a complex structure. An example can be the following Course object (JavaScript):


var Course = new Object();
Course.Name = "CRM Development 1";
Course.Teacher = "Prof. John Smith";

Course.Students = new Array();
Course.Students[0] = new Object();
Course.Students[0].ID = "001";
Course.Students[0].Name = "Walter Davis";

Course.Students[1] = new Object();
Course.Students[1].ID = "002";
Course.Students[1].Name = "Mark Harris";

var parameter1 = JSON.stringify(Course);

Because I was inside a Sandbox plugin I couldn’t use the Newtonsoft.Json library and I didn’t want to waste time trying to merge it inside my plugin.

The .NET framework provides different methods to create a JSON output, in particular JavaScriptSerializer (fromSystem.Web.Script.Serialization namespace) and DataContractJsonSerializer (fromSystem.Runtime.Serialization.Json namespace).

JavaScriptSerializer is very easy to use (it has a Serialize method returning a string) but doesn’t work inside Sandbox, so I used DataContractJsonSerializer:


Course course = new Course();
// ...

string parameter1 = "";
using (MemoryStream memoryStream = new MemoryStream())
{
   DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Course));
   serializer.WriteObject(memoryStream, course);
   parameter1 = Encoding.Default.GetString(memoryStream.ToArray());
}

A bit longer code but compatible with Sandbox and CRM Online.

Processing JSON within a CRM Plugin

[Originally Posted By]: https://prasadiapsara.wordpress.com/2015/11/09/processing-json-within-a-crm-plugin/

mq1                        json_logo-555px

Even though there are so many interesting and straightforward .NET libraries to process JSON  such as Json.NET, that is not going to work with MS Dynamics CRM Plugins. Because we cannot reference third party assemblies from a plugin assembly. There are some ways that you can refer a third party assembly such as ‘Assembly Merging’, but they are intense and time consuming.

So if we are to process JSON from a CRM plugin below approach can be followed.

  1. Serializing a JSON object
  • Add a Data Contract Class representing the JSON Model
[DataContract]
public class RefundReviewRequest
{
    //datamember name value indicates name of json field to which data will be serialized/from which data will be deserialized
    [DataMember(Name = "refundId")]
    public string refundId { get; set; }

    [DataMember(Name = "refundFee")]
    public string refundFee { get; set; }

    [DataMember(Name = "refundPhase")]
    public string refundPhase { get; set; }

    public RefundReviewRequest() { }
}
  • Create an object using the data contract
RefundReviewRequest refundRequest = new RefundReviewRequest
                        {
                            refundId = postImageEntity.Attributes["nxt_refundid"].ToString(),
                            refundFee = postImageEntity.Attributes["nxt_refundfee"].ToString(),
                            refundPhase = postImageEntity.Attributes["nxt_refundphase"].ToString()
                        };
  • Serialize the object created and pass it through a web stream
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(refundRequest.GetType());
                        MemoryStream ms = new MemoryStream();
                        serializer.WriteObject(ms, refundRequest);
                        string jsonMsg = Encoding.Default.GetString(ms.ToArray());
                        var uri = new Uri('http://testURIString');
 
                        var request = WebRequest.Create(uri);
                        request.Method = WebRequestMethods.Http.Post;
                        request.ContentType = "application/json";
                        byte[] bytes = System.Text.Encoding.ASCII.GetBytes(jsonMsg.ToString());
                        request.ContentLength = bytes.Length;
 
                        System.IO.Stream os = request.GetRequestStream();
                        os.Write(bytes, 0, bytes.Length);
                        os.Close();

2. De-serializing a JSON Object

  • Add a data contract class to represent the JSON object
[DataContract]
public class RefundReviewResponse
{
    //datamember name value indicates name of json field to which data will be serialized/from which data will be deserialized
    [DataMember(Name = "refundId")]
    public string refundId { get; set; }

    [DataMember(Name = "status")]
    public string status { get; set; }

    [DataMember(Name = "message")]
    public string message { get; set; }

    public RefundReviewResponse() { }
}
  • De-serialize a JSON response and process it
using (var response = request.GetResponse())
{
    RefundReviewResponse refundResponse = new RefundReviewResponse();
    System.Runtime.Serialization.Json.DataContractJsonSerializer deserializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(refundResponse.GetType());
    refundResponse = deserializer.ReadObject(response.GetResponseStream()) as RefundReviewResponse;
    entOrderProduct.Attributes["nxt_refundreviewresponse"] = refundResponse.status;

    if (refundResponse.status != "101")
    {
       
    }
}