Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

VS2008 protected memory read exception

I have an application which works in VS2005, and sort of works in VS2008. The code causing me a problem is as follows

double mse;
double[] coefficients;
double[] fitted;
fitted = CurveFit.PolynomialFit(_x, _stress, Convert.ToInt32(PolynomialOrder), PolynomialFitAlgorithm.Svd, out coefficients, out mse);

In 2008 whenever PolynomialOrder is > 6 the following exception is thrown, whereas in VS2005 it works for order 8.

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at NationalInstruments.Analysis.Internal.k.a(Double[] A_0, Double[] A_1, Int32 A_2, Int32 A_3, Int32[] A_4, Double[] A_5, Int32 A_6, PolynomialFitAlgorithm A_7, Double[] A_8, Double[] A_9, Double& A_10)
   at NationalInstruments.Analysis.Math.CurveFit.PolynomialFit(Double[] inputXData, Double[] inputYData, Int32 order, PolynomialFitAlgorithm fitAlgorithm, Double[]& coefficients, Double& mse)
   at TWI.Crackwise.Stresses.GeneralWeightFunction.FitCurve(Double normaliser, Double thickness, String& error)
   
This is using the date listed below.

I'm using c# with the following components
NationalInstruments.Analysis.Enterprise 8.1.20.377
NationalInstruments.Common 8.1.20.235


This seems very strange as the 2008 version still targets a .Net 2.0 target.

Anyone got any ideas ?

Thanks

Paul


_x,_stress
0,377.948
0.253912,294.315
0.503124,127.076
0.75217,-40.8975
1.005592,-177.109
1.06369,-248.745
1.12695,-267.776
1.19577,-265.571
1.270692,-261.975
1.352252,-257.119
1.440992,-251.003
1.537592,-242.917
1.642732,-232.234
1.757172,-218.715
1.881732,-201.758
2.0173,-180.679
2.16484,-154.717
2.32542,-122.902
2.5002,-84.0814
2.69044,-36.6377
2.89748,21.0256
3.12282,90.867
3.3681,175.009
3.63504,275.756
3.92,330.645


0 Kudos
Message 1 of 48
(9,929 Views)
Hi Paul,
 
We don't officially support Visual Studio 2008 yet but we are working on it. Regardless, our assemblies should work in Visual Studio 2008. I created a quick example and used an order of 8 and had no problems in 2008. Here is the snippet of code I used to test.  Now I am using a later version of our Analysis assembly but we didn't change anything that would affect what you are seeing.  Can you try this code below in 2008 and see what happens. If this works, then I am inclined to think it has something to do with your specific code. In that case, can you either zip up and post your code snippet so I can run it directly in 2008. Posting a 2008 project would be the easist as I could just open and run it.
 
int numSamples = 9;

double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };

double[] yData = new double[] { 1.00, 2.70, 7.40, 150.00, 80.00, 220.00, 150.00, 70.0, 80.0 };

double[] specifiedCoefficients, coefficients = new double[numSamples];

double[] weight = new double[numSamples];

double[] fittedData = new double[numSamples];

int[] specifiedOrder = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

int order;

double mse;

 

// Generate a ramp pattern that represents specifiedCoefficients

specifiedCoefficients = PatternGeneration.Ramp(numSamples, 0.0, 15.0);

 

for (int i = 0; i < weight.Length; i++)

    weight[i] = 1.0;

 

order = 8;

 

// Calculate polynomial fit of the data set {xData, yData}

// fittedData = CurveFit.PolynomialFit(xData, yData, weight, order, PolynomialFitAlgorithm.Svd, specifiedOrder, specifiedCoefficients, out coefficients, out mse);

fittedData = CurveFit.PolynomialFit(xData, yData, order, PolynomialFitAlgorithm.Svd, out coefficients, out mse);

 

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 2 of 48
(9,931 Views)
I tried with your data and it worked ok, however switching to my still data causes the problem.
I've attached the dummy solution I just used to show this (The Work button is your Data, and the Throw Exception Button is my data).


I do have the later version of Measurement Studio, but I can't upgrade at the moment as we're very close to a different product shipment (within a week) and I don't want to throw that potential change in to the mix yet.

Paul
0 Kudos
Message 3 of 48
(9,929 Views)
Hi Paul,
 
Your code actually works for me in VS 2008 so it appears something did change but I am not sure what is was. I assume you will be building your application against VS2005 correct? VS 2005 is fully supported by us right now and it appears everything works with that version.
 
Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 4 of 48
(9,928 Views)
I will be building the release app against 2005 for the time being, however I'm concerned that there is this difference and no explanation for it. After all it's still a .Net 2.0 targetted application. Is there a chance of someone looking into what has changed to cause this, and whether or not it could have other side effects for our 2005 build as this seems data dependent ?

Paul
0 Kudos
Message 5 of 48
(9,925 Views)
Hi Paul,

We will be looking into this issue further so this issue will not go unnoticed.  We first have to reproduce the problem on our side in earlier versions of our assemblies or underlying DLL components.  I will post back to the forum when a solution is found. 

We need to do further testing to state whether its data dependent, a bug we introduced, etc. At this time, I can't state what's going on because we haven't dug into the code yet.
 
Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 6 of 48
(9,928 Views)
Hi Paul,

Well I just installed Measurement Studio 8.1.1 on a fresh clean machine with Visual Studio 2005 and Visual Studio 2008 installed. I ran the exact program that you sent me and I didn't receive the errors you were seeing in Visual Studio 2008.  I double-checked my assembly versions and they were the same as yours. 

Does this error occur on multiple machines or just one?

What version of nianlys.dll do you have in the <National Instruments>\Shared\Analysis\ directory? I have version 8.1.1.359. 

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 7 of 48
(9,875 Views)
I've only tried on one machine (my dev machine) so can't say about any others. I've just tried on a different machine (server 2003) and it was Ok on there.

The nianlys.dll version is 8.1.1.361

My dev machine is vista, is it possible that that's having and effect ?

Paul
0 Kudos
Message 8 of 48
(9,874 Views)
I've just tried on a different vista machine and it was fine on that too, any ideas why it won't work on this particular machine ?

Thanks

Paul
0 Kudos
Message 9 of 48
(9,872 Views)
I've tried on a few more machines today and there was another machine with the same problem (another vista laptop), so out of 6 machines tested it fails on 2 vista machines, the tested machines were
dell D620 notebook running vista  - Fail
dell precision M70 notebook running vista  - Fail
Generic 2.8GHz P4 desktop pc running vista - Pass
dell precision M70 notebook running XP- Pass
VMWare virtual machine running XP - Pass
Dell 2950 server running 2003 - Pass
.
Unfortunately I don't have a virtual Vista PC to test on at the moment.

Paul

0 Kudos
Message 10 of 48
(9,860 Views)