Problem setting parameters of spatial projection programatically

Discussion created by TartanRug on May 28, 2012

I am creating a set of feature classes in Arcgis programmatically (with vb.net) and I need to set the spatial reference for each feature class.

I am having a problem setting the x,y origin for each class. I can set the Central Meridian ok (for the origin of the x coord) but when I try to use Central Parallel to set the origin of the y-coord I get an 'Arcgis desktop has encountered a serious application error and is unable to continue' error.

Here is a snippet of the code, pOrigin.X and pOrigin.Y are both doubles.

Dim pMap As IMap
Dim pMxDoc As IMxDocument

pMxDoc = CType(m_application.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument)
pMap = pMxDoc.FocusMap

Dim pSpatialReference = pMap.SpatialReference
Dim pProjectedCoordinateSystem As IProjectedCoordinateSystem
pSpatialReference = pMap.SpatialReference
pProjectedCoordinateSystem = pSpatialReference 'QI
pProjectedCoordinateSystem.CentralMeridian(True) = pOrigin.X
pProjectedCoordinateSystem.CentralParallel = pOrigin.Y

Any idea what is causing the error? Any help appreciated!