Topics
30 Apr 2014, 16:53
 4910
 9
Replies

aaante
11 May 2014, 14:28

RE:

Invalid:

Library I'm trying to call from cAlgo was created using MATLAB Builder NE. The line of code where String.Replace is called I found in source code that comes with compilation, and is standard for all libraries created using MATLAB Builder NE. I suppose:

string ctfFilePath = assembly.Location;

returns empty string and consequently

ctfFilePath= ctfFilePath.Remove(lastDelimiter, (ctfFilePath.Length - lastDelimiter));

returns -1.

The exception is thrown only when library is called from cAlgo code. In all other cases calling library works fine.

I tried to call

Assembly assembly = Assembly.GetExecutingAssembly();
Print(assembly.Location);

in Calculate() method also but empty string is returned also. Support why is that?


@aaante

aaante
08 May 2014, 15:11

RE: RE:

Invalid said:

aaante said:

Tnx, but second exception appeared when method is called:

System.TypeInitializationException: The type initializer for 'Volatility.rm94class' threw an exception. ---> 
System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. Parameter name: startIndex    
at System.String.Remove(Int32 startIndex, Int32 count)    
at Volatility.rm94class..cctor()    
--- End of inner exception stack trace ---    
at Volatility.rm94class..ctor()    
at cAlgo.CustomSTD.Calculate(Int32 index)


 

do you call any method String.Remove(Int32 startIndex, Int32 count)  in your code?

Problem lies in assembly location. Only time String.Replace could be called is within matlab compiled .dll (lower code). Any ideas why?

/// <summary internal= "true">
/// The static constructor instantiates and initializes the MATLAB Compiler Runtime
/// instance.
/// </summary>
static rm94class()
{
    if (MWMCR.MCRAppInitialized)
    {
        Assembly assembly = Assembly.GetExecutingAssembly();
        string ctfFilePath = assembly.Location;
        int lastDelimiter = ctfFilePath.LastIndexOf(@"\");
        ctfFilePath= ctfFilePath.Remove(lastDelimiter, (ctfFilePath.Length - lastDelimiter));
        string ctfFileName = "Volatility.ctf";
        Stream embeddedCtfStream = null;
        String[] resourceStrings = assembly.GetManifestResourceNames();
        foreach (String name in resourceStrings)
        {
            if (name.Contains(ctfFileName))
            {
                embeddedCtfStream = assembly.GetManifestResourceStream(name);
                break;
            }
        }
        ...

@aaante

aaante
30 Apr 2014, 18:15

Tnx, but second exception appeared when method is called:

System.TypeInitializationException: The type initializer for 'Volatility.rm94class' threw an exception. ---> 
System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. Parameter name: startIndex    
at System.String.Remove(Int32 startIndex, Int32 count)    
at Volatility.rm94class..cctor()    
--- End of inner exception stack trace ---    
at Volatility.rm94class..ctor()    
at cAlgo.CustomSTD.Calculate(Int32 index)


 


@aaante

aaante
30 Apr 2014, 17:27

RE:

aaante said:

Has anyone successfully used .dll compiled in Matlab?

In my case program always throws an exception on initialization of any object from MWArray.dll or compiled .dll.

For example, when I tried to initialize MWNumericArray inside Calculate method:

Crashed in Calculate with TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWNumericArray' threw an exception.

I tried to call it directly from cAlgo (indicator, robot) and from outside .dll (Class Library), but with no success. I used dlls successfuly when developing in VS.

Any ideas?

previous exception was caught wit catch(MWException e). Same exception caught with catch(Exception e):

System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWNumericArray' threw an exception. ---> 
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.    
at MathWorks.MATLAB.NET.Utility.MWSafeHandle..ctor()    
at MathWorks.MATLAB.NET.Arrays.MWNumericArray..ctor(Double scalar)    
at MathWorks.MATLAB.NET.Arrays.MWNumericArray.get__Inf()    
at MathWorks.MATLAB.NET.Arrays.MWNumericArray..cctor()    
--- End of inner exception stack trace ---    
at MathWorks.MATLAB.NET.Arrays.MWNumericArray..ctor(Int32 realValue, Int32 imaginaryValue)    
at cAlgo.CustomSTD.Calculate(Int32 index)

 


@aaante