NET.addAssembly given arithmetic overflow

3 views (last 30 days)
I am using a toolbox that makes use of a NET.addAssembly (developed by DHI namely to read in result files of their software). I am however not familiar with this NET.addAssembly programming and when I adjusted one of their files, I am getting the following error message when I try to read in the result file:
MATLAB:NET:CLRException:PropertyGet
Message: Arithmetic operation resulted in an overflow.
What can be causing this? The line that is called cannot lead to an overflow as it only contains 123 doubles as a result. I have also been careful to always close the file that I have opened with the close function provided (through an OnClean-up function).
First the problem only occurred after several calls to my function were made in the same matlab-session and it helped to close matlab and open again. But now I get this error message every time, even after restarting my computer!, so I cannot run my function any more.
What should I look for in my code?
  13 Comments
Guillaume
Guillaume on 4 Sep 2014
You say that sometimes it is available and other times not as it is the same file that is being read in each time, but from your example it would appear that the property is always available for res11File.ItemInfo.Item(0) and never available for res11File.ItemInfo.Item(4) (for that particular file).
Can you confirm that's what you're seeing, or is it sometimes available for the same item and sometimes not?
Ingrid
Ingrid on 4 Sep 2014
Edited: Ingrid on 4 Sep 2014
it is always available for res11File.ItemInfo.Item(0) but after that the number for which it is not available varies. Sometimes already for res11File.ItemInfo.Item(1), last time it was for res11File.ItemInfo.Item(4), but sometimes it goes all the way to res11File.ItemInfo.Item(25) which is the maximum for this file and no error occurs at all. This is however only when I have not compiled any mex-code
the reason I think the mex-compiling has something to do with it is because first the function works completely and then after a first compilation it worked up to 4 and after a second compilation it worked up to 1
the code for the mex compilation is just
mex -g modelName.c
so should not cause any problems

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 4 Sep 2014
From the name of the class, it looks like DHI have implemented some sort of dynamic object with dynamic properties. I've no idea how they've done it since your object does not even derive from DynamicObject.
In any case, since you don't have any control over the object behaviour, I think the best you can do is check if the property exists before calling it:
for ii = 1:res11File.ItemInfo.Count
itemInfo = res11File.ItemInfo.Item(ii-1);
if any(strcmp(properties(itemInfo), 'SpatialAxis'))
coords = itemInfo.SpatialAxis.Coordinates;
%do something with coords
else
%sorry coords not available. make do without (use a default?)
end
end
Or you could wrap your call in a try catch:
for ii = 1:res11File.ItemInfo.Count
itemInfo = res11File.ItemInfo.Item(ii-1);
try
coords = itemInfo.SpatialAxis.Coordinates;
catch err
if strcmp(err.identifier,'MATLAB:NET:CLRException:PropertyGet')
coords = somedefaultvalue
else
rethrow(err); %some other error. Better tell you about it.
end
%do something with coords
end
  5 Comments
Ingrid
Ingrid on 5 Sep 2014
Edited: Ingrid on 5 Sep 2014
OK, thank you very much for you answer. I will try to re-organize my code to take this into account and issue a warning to the user when it does happen as it will be part of a larger program. Hopefully it will be resolved in a next version or someone else will have an idea on how to proceed
Guillaume
Guillaume on 5 Sep 2014
Edited: Guillaume on 5 Sep 2014
I didn't see the first time round the short extract of the manual that you've posted. it's not really anything to do with the issue you're having, it only talks about another method (COM) of communicating with their code.
However, you can also use COM from matlab. As your document says it's a bit more awkward than the .Net interface but maybe it'd work better.
You would have to find the ProgId of the COM interface, it should be somewhere in the documentation. Then you would access your file with something like:
dfsreader = actxserver('DFSProgId.DfsFileFactory'); %possibly
dfshelper = actxserver('DFSProgId.DfsComHelper'); possibly
res11File = dfsreader.DfsGenericOpen(infile);
%as explained you need to use the DfsComHelper to access iteminfo
iteminfos = dfshelper.GetItemInfoDfs(res11File);
for ii = 1:iteminfos.Count
iteminfo = iteminfos.Item(ii-1);
coords = iteminfo.SpatialAxis.Coordinates; %possibly
%...
end
%at the end, release the COM interfaces
delete(dfshelper);
delete(dfsreader);
It might be a bit more complicated if any object you need implements several interfaces as you may need to switch interface to access the right method (as explained in the 2nd part of your document), which you would do using invoke. For example, according to that doc, IDfsFile has two more interfaces
interfaces(res11File)
%should return {'ProgId.IDfsFileIO', 'ProgId.IDfsFileStaticIO'}
%use a different interface:
res11FileAsFileIO = invoke(res11File, 'IDfsFileIO');
res11FileAsFileIO.methodofFileIO(...);

Sign in to comment.

More Answers (1)

xu chen
xu chen on 26 Nov 2019
I had the same problem as you. Excuse me, how did you solve it in the end? Thank you very much!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!