Monday, September 27, 2010

Framework change causes exception: Cannot marshal '': Invalid managed/unmanaged type combination ... ?

Programmer Question

From my managed code (let's call it MyLib) I am using a library (let's call it OtherLib) that is basically a wrapper around some c++ code (I have never seen the wrapper code or have had access to its source, nor will I have it).



When my calling library is targetting the 3.5 framework all is good and dandy. When I make it target .NET 4.0 I am getting this exception when using a method from OtherLib:



Cannot marshal 'parameter #3': Invalid managed/unmanaged type combination (this value type must be paired with Struct).



This happens, when I am calling a method on one of the types supplied by the wrapper. On line 4 I get above stated exception.



            If results.Compute(coordOrg, True, Nothing) Then
For Each Coord As Coordinate3D In queueDest
resDM(fromIndex, Coord.zMeter, DistanceCostType.CrowFly) = Math.Round(Math.Sqrt(Math.Pow(pointFrom.X - Coord.xMeterOrLongDeg, 2) + Math.Pow(pointFrom.Y - Coord.yMeterOrLatDeg, 2)) / 1000, 6)
resDM(fromIndex, Coord.zMeter, DistanceCostType.Road) = Math.Round(results.GetCost(Coord, m_itiDistance) / 100000, 6)
resDM(fromIndex, Coord.zMeter, DistanceCostType.Time) = Math.Round(results.GetCost(Coord, m_itiTime) / 100 / 60, 4)
Next
End If


Has anyone encountered something similar ?



EDIT:
I have tried switching the targetting from 3.5 to 4.0 and back again. Under 3.5 all work fine under 4.0 it throws this exception.
I have tried creating a wrapper project targetting 3.5, exposing a static class retrieving results from the OtherLib. Again when I call it from project compiled to 4.0 it fails and works when compiled for 3.5



EDIT2: Enum definition



Public Enum DistanceCostType
CrowFly
Road
Time
End Enum


Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails