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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Plugin Error "An unexpected error occurred from ISV code"

(0) ShareShare
ReportReport
Posted on by 92

I added a plugin on create of a new form it takes l list specified on the form and takes the equipment inside the list to create for each equipment a station equipment.
when I register the plugin on Create it doe not create any station equipment. when i remove the relation between station equipment and the project station (in the code) the records are created.
of course, I tried to use the profiler and debugged the problem, but when debugging the code runs normally without any issue (with relation too).

I tried to register the step on update to debug and got this error "An unexpected error occurred from ISV code." I tried checking the error and I think it means my code is entering an infinite loop. So, I tried to debug again and the code works fine when debugging.

of course, the step is registered on post-operation synchronous.

this is the code below

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.PrimaryEntityId != null)
{
Entity entity = (Entity) context.InputParameters["Target"];

EntityReference projStationRef = new EntityReference("mfex2193_projectstation", context.PrimaryEntityId);

Entity prjStation = Functions.GetProjStationDet(service, context.PrimaryEntityId);

EntityReference station = prjStation.Contains("mfex2193_station") ? prjStation.GetAttributeValue<EntityReference>("mfex2193_station") : null;
EntityReference list = (prjStation.Contains("mfex2193_equipmentlist") ? prjStation.GetAttributeValue<EntityReference>("mfex2193_equipmentlist") : null) ?? throw new InvalidPluginExecutionException("Please choose a list.");
List<Entity> relatedEqu = Functions.GetRelatedEquipments(service, list.Id);

if (relatedEqu != null)
{
List<Entity> insertEnt = new List<Entity>();
foreach (Entity equipment in relatedEqu)
{
var equName = equipment.Contains("Equipment.mfex2193_name") ? equipment.GetAttributeValue<AliasedValue>("Equipment.mfex2193_name").Value.ToString() : "";
EntityReference equRef = new EntityReference("mfex2193_equipment", (Guid)equipment.GetAttributeValue<AliasedValue>("Equipment.mfex2193_equipmentid").Value);

//throw new InvalidPluginExecutionException(projStationRef.Id.ToString());

Entity newEnt = new Entity("mfex2193_stationequipment")
{
//Id = Guid.NewGuid(),
Attributes =
{
new KeyValuePair<string, object>("mfex2193_name",equName),
new KeyValuePair<string, object> ("mfex2193_station", station),
new KeyValuePair<string, object> ("mfex2193_equipment", equRef),
new KeyValuePair<string, object> ("mfex2193_projectstation", projStationRef)
}
};


insertEnt.Add(newEnt);
}

Functions.BulkInsert(service, insertEnt);
}
}

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 156

#2
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans