I made a very simple program with C# VS2017 and Matlab 2012b:
namespace TestConMatlab
{
class Program
{
static void Main(string[] args)
{
try
{
var matlab = new MatlabFunction();
double[] data = { 1, 2, 3 };
double[,] r = (double[,])matlab.doMedian(data.ToArray());
Console.Out.Write("OK: " + r.ToString());
} catch( Exception ex )
{
Console.Out.Write(ex.ToString());
}
Console.ReadLine();
}
}
}
This program run on mulitple PC, but on one computer I have :
System.Exception:
... MWMCR::EvaluateFunction error ...
Undefined function 'doMedian' for input arguments of type 'double'..
at MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(String functionName, Int32 numArgsOut, Int32 numArgsIn, MWArray[] argsIn)
at MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(String functionName, Object[] argsIn)
at MatlabFunctionNative.MatlabFunction.doMedian(Object input)
at TestConMatlab.Program.Main(String[] args) in C:\Users\User\source\repos\TestConMatlab\Program.cs:line 18
Of course I have installed the same Matlab MCR v8.0. I have trace some API call with procmon but I did not find solution.
I have deleted the folder C:\Users\%USER%\AppData\Local\Temp\%USER%\mcrCache8.0
Remove MCR and delete manualy C:\Program Files (x86)\MATLAB, and after restart, program work !
Related
The question can be asked in another way, but I'm not sure which one is possible:
How to force the runtime to disable method inline?
Problem
I have a library assembly (no source code), some methods are marked with AggressiveInlining:
CSharpLib
public class ExceptionTest
{
private int[] a;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void A()
=> B();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void B()
=> a[0] = 1;
}
The assembly is built in Debug mode (with "Optimize code" unchecked).
In my program I need to call the method A:
My program
static void Main(string[] args)
{
try
{
new CSharpLib.ExceptionTest().A();
}
catch (NullReferenceException e)
{
Console.WriteLine(e.ToString());
}
}
Even if the program is run in Debug mode, it only prints one line:
at Program.Main(String[] args)
So I wonder if I can get a stacktrace with method A and B involved?
My attempts
Both Environment.StackTrace and new StackTrace(true) return the same one frame.
If I put a break point at the end of the catch block and watch e.StackTrace and e, The value of e.StackTrace is the same as above, but the value of StackTrace under e is full:
at CSharpLib.ExceptionTest.B()
at CSharpLib.ExceptionTest.A()
at Program.Main(String[] args)
But I need log the stacktrace, so I cannot just refer the text here.
I'm attempting to remove several registry keys in the event that a program doesn't uninstall correctly.
I'm compiling my program using Any CPU and running the program on Windows 10 Pro (64 bit).
I am receiving the following exception:
System.IO.IOException: No more data is available.
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.InternalGetSubKeyNames()
at Microsoft.Win32.RegistryKey.GetSubKeyNames()
at ...
when I run the following code:
string[] items_list = new[]
{
"string1",
"string2",
"string3"
// ...
};
foreach (string subKeyName in Registry.ClassesRoot.GetSubKeyNames())
{
if (items_list.Any(item => subKeyName.StartsWith(item)))
{
DeleteSubKeyTree(Registry.ClassesRoot, subKeyName);
}
}
void DeleteSubKeyTree(RegistryKey regKey, string subKey)
{
try
{
regKey.DeleteSubKeyTree(subKey);
WriteToLog($#"Deleting sub key {subKey} from {regKey.Name}.");
}
catch (Exception ex)
{
WriteToLog(ex.Message);
}
}
Following code produces same output on 95% of machines, but on several there is difference. In Debug mode there is output:
Changing from New to Fin
OK
but in Release mode:
Changing from New to Fin
The OK line is missing. The project is targeted to .Net 4.0, build with VS 2015. You can download full sample here.
Source code
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Status current = Values.Status;
if (current != Next())
Console.WriteLine("OK");
}
static VO Values = new VO();
private static Status Next()
{
Status res = Status.Fin;
if (Values.Status == Status.New && Values.Cond)
res = Status.Fin;
else if (Values.Status == Status.Fin)
res = Status.Fin;
Log("Changing from {0} to {1}", Values.Status, res);
Values.Status = res;
return res;
}
public static void Log(string format, params object[] args)
{
Console.WriteLine(format, args);
}
}
public class VO
{
public Status Status;
public bool Cond;
}
public enum Status { New, Fin }
}
This is in my opinion the minimal version to reproduce the error. After removing some of the conditions in Next(), inlining Log method, replacing Values.Cond with false causes the application behaves correctly.
Edit: It's not hardware related - operating system was extracted to Hyper-V and the problem persists.
Based on Hans Passant's comment the problem was still reproducible with clrjit.dll version 4.6. After upgrading to 4.7 it disappears.
I am trying to install VFPOLEDB driver via a console application.
I tried doing something like this
public void InstallVfpOledb()
{
Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
try
{
Installer installer = (Installer)Activator.CreateInstance(type);
installer.InstallProduct(#"C:\VFPOLEDBSetup.msi");
}
catch (Exception e)
{
Console.Write(e.ToString());
}
}
So when I run the program I get the following exception:
System.Runtime.InteropServices.COMException (0x80004005):
InstallProduct,PackagePath,PropertyValues at
System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData) at WindowsInstaller.Installer.InstallProduct(String
PackagePath, String PropertyValues) at
installtest.Program.Main(String[] args) line 22
I believe InstallProduct method has path and property values as parameters.
I am missing those values I guess.
Can anyone point me in the correct direction for the same?
This one works for me:
// using Microsoft.Deployment.WindowsInstaller in
// Microsoft.Deployment.WindowsInstaller.dll
try
{
Installer.InstallProduct(#"C:\VFPOLEDBSetup.msi","");
}
catch (Exception e)
{
Console.Write(e.Message);
}
It asks for permission if not run as administrator.
I'm developing in C#, and using Dotnetzip's Source code to get the application in one file.
But when running, i get the exception:
System.OverflowException: Arithmetic operation resulted in an overflow.
at Ionic.Crc.CRC32..ctor(Int32 polynomial, Boolean reverseBits) in DotNetZip\CRC32.cs:line 452
at Ionic.Crc.CRC32..ctor(Boolean reverseBits) in DotNetZip\CRC32.cs:line 418
at Ionic.Crc.CRC32..ctor() in DotNetZip\CRC32.cs:line 398
at Ionic.Crc.CrcCalculatorStream..ctor(Boolean leaveOpen, Int64 length, Stream stream, CRC32 crc32) in DotNetZip\CRC32.cs:line 622
at Ionic.Crc.CrcCalculatorStream..ctor(Stream stream) in DotNetZip\CRC32.cs:line 519
at Ionic.Zip.ZipEntry.ExtractOne(Stream output) in DotNetZip\ZipEntry.Extract.cs:line 1043
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password) in DotNetZip\ZipEntry.Extract.cs:line 870
at Ionic.Zip.ZipEntry.Extract(String baseDirectory, ExtractExistingFileAction extractExistingFile) in DotNetZip\ZipEntry.Extract.cs:line 240
at ItxInstaller.Package.GetData(String instFilePath) in Package.cs:line 32
at ItxInstaller.Install..ctor() in Install.cs:line 26
at ItxInstaller.Program.Main(String[] args) in Program.cs:line 54
The Install.cs is like this:
public Install()
{
// The InitializeComponent() call is required for Windows Forms designer support.
this.InitializeComponent();
Package pack = Package.GetData(Program.args[1]);
this.Title.Text = pack.AppName;
this.PathBox.Text = pack.GeneratePath();
}
The Package.cs contains the GetData():
class Package
{
public string AppName;
public string ExePath;
private string FilePath;
public Package(string filePath)
{
this.ValueInit(filePath);
this.FilePath = filePath;
}
public static Package GetData(string instFilePath)
{
using (ZipFile Package = ZipFile.Read(instFilePath))
{
Package["app.itx"].Extract(Path.GetTempPath(), ExtractExistingFileAction.OverwriteSilently);
}
return new Package(Path.Combine(Path.GetTempPath(), "app.itx"));
}
}
How to solve this exception?
I can reproduce this problem with Mono when using "-checked+" as parameter, i.e. with enabled arithmetic checks. Omitting this parameter results in a working executable.
There is also a project setting for it in Visual Studio.
I've extracted the relevant code into this working program so you can test it yourself:
using System;
namespace Test {
public class Program {
public static void Main(string[] args) {
CRC32 test = new CRC32();
Console.Out.WriteLine(test.dwPolynomial);
}
}
public class CRC32 {
public UInt32 dwPolynomial;
public CRC32() : this(false) {
}
public CRC32(bool reverseBits) :
this(unchecked((int)0xEDB88320), reverseBits) {
}
public CRC32(int polynomial, bool reverseBits) {
this.dwPolynomial = (uint) polynomial; // this is line 452
}
}
}
Using dcms test.cs && mono test.exe runs fine.
Using dcms -checked+ test.cs && mono test.exe results in a
Unhandled Exception: System.OverflowException: Number overflow.
at Test.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Number overflow.
at Test.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
Update: if you can't or don't want to disable arithmetic checks then you could modify the source code of like 452 to
this.dwPolynomial = unchecked((uint) polynomial);
This turns off arithmetic checks for the expression.