Exception while installing VFPOLEDB programmatically - c#

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.

Related

Matlab MWMCR::EvaluateFunction error in C# on one system

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 !

C# exception System.ArgumentException in dynamic object

I have the following code interacting with automation server via dynamic object:
class Program
{
static string strProgId = "MyAutomation.Document";
static dynamic pserver = null;
static void Main(string[] args)
{
try
{
Type tPserver = Type.GetTypeFromProgID(strProgId);
if (tPserver != null)
{
pserver = Activator.CreateInstance(tPserver);
}
pserver.About(null, 0);
pserver.OpenDataFile(IntPtr.Zero, true, "Test.dat");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
if (pserver != null)
{
pserver.FileExit();
}
}
}
As you can see, it creates an instance of automation server and is calling two methods on it. The first call works as expected. The second call throws the following exception:
e {"Could not convert argument 0 for call to OpenDataFile."} System.Exception {System.ArgumentException}
Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary> {System.Collections.ListDictionaryInternal}
HResult 0x80070057 int
I am not sure what is wrong here, since both methods have the same argument 0 and the first call works as expected. These methods are defined in ODL file as follows:
[id(20)] boolean About(long hWnd, long msgID);
[id(35)] boolean OpenDataFile(long hWnd, boolean bEmbed, BSTR* bsPfyFilePath );
Thank you for your help.

NLog: logger.Error(string, Exception, param objects[] args) function doesn't log my exception

I'm having a problem logging my exceptions using this piece of code:
Logger.logger.Error("Exception occured", ex, "");
because it only logs the message but when I use the same function with 2 arguments supplied in it then it will work, though it is obsolete that's why I'm reluctant in using it.
This is the piece of code that is working and i'm currently using:
Logger.logger.Error("Exception occured", ex);
Any help would be appreciated. Thanks!
seems like you mistook parameters order. An exception should be first, second is a message
From NLog sources
public void Error(Exception exception, [Localizable(false)] string message)
public void Error(Exception exception, [Localizable(false)] string message, params object[] args)
NLog changed the functions.
In some older Version you had:
_logger.ErrorException("My Message", myException);
Now the first param ist of Type Exception:
_logger.Error(myException, "My Message: {0}", myException.Message);
..ErrorException() is now obsolete..

XamlServices.Load exception message truncated when running in nunit test

here's my problem.
I have the following unit test:
[Test]
public void ShouldParseXaml()
{
try
{
XamlServices.Load("Filel.xaml");
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}
When this unit test is run automatically via a GUI test runner, I get the following exception message:
Add value to dictionary of type 'System.Collections.Generic.Dictionary(System.UInt32,
System.Collections.Generic.List(MyXamlFramework.IConfigurationFieldNameProvider))'
threw an exception.
at NUnit.Framework.Assert.Fail(String message, Object[] args)
at NUnit.Framework.Assert.Fail(String message)
at XamlBehaviour.ShouldParseXaml3() in C:\test\XamlBehaviour.cs:line 62#0
If however, I place a breakpoint on the Assert.Fail(e.Message) and then continue to let the test run after it breaks, I get following exception message:
'Add value to dictionary of type 'System.Collections.Generic.Dictionary(System.UInt32,
System.Collections.Generic.List(MyXamlFramework.IConfigurationFieldNameProvider))'
threw an exception.' Line number '70' and line position '11'.
at NUnit.Framework.Assert.Fail(String message, Object[] args)
at NUnit.Framework.Assert.Fail(String message)
at XamlBehaviour.ShouldParseXaml3() in C:\test\XamlBehaviour.cs:line 62#0
If possible, I'd really like to retain the full exception message which includes the line and position number when the test is auto run.
Thanks for your help.

How to properly handle COMException when writing to Excel cell?

I have an application which writes values to one of 4 cells in an Excel worksheet. The sheet is roughly 30x30 cells. Normally this works fine but if the user happens to click on the worksheet while my app is running then a COMException is thrown. Note that the cell that is clicked on does not have to be one of those that is being written to by the app. I tried doing 3 retries (see code below) but this did not help.
What might be causing this error and what can I do to handle it better?
public bool WriteString(string id, string value)
{
for (int i = 0; i < RETRY; i++)
{
try
{
log.Debug(string.Format("XL write '{0}' to '{1}'", value, id));
Range range = GetCell(id);
range.Value2 = value;
return true;
}
catch (System.Runtime.InteropServices.COMException x)
{
log.Error(x);
Thread.Sleep(1);
}
}
return false;
}
System.Runtime.InteropServices.COMException (0x800AC472): Exception from HRESULT: 0x800AC472
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.Range.set_Value2(Object value)
at Pruef.Net.TgtManager.StdTarget.Excel.ExcelTarget.WriteString(String id, String value)
at Pruef.Net.TgtManager.StdTarget.Excel.ExcelTarget.WriteDouble(String id, Double value)
at Pruef.Net.Model.IOManaged.DoOutput(OutputAction action)
at Pruef.Net.ViewModel.ExecuteViewModel.PerformAction(BaseAction action, Boolean ignoreStop)
at Pruef.Net.ViewModel.ExecuteViewModel.PerformAction(BaseAction action, Boolean ignoreStop)
at Pruef.Net.ViewModel.ExecuteViewModel.PerformActions(ObservableCollection`1 actions, Boolean ignoreStop)
at Pruef.Net.ViewModel.ExecuteViewModel.Execute(UnitOfTest uot)
Just found this question Exception from HRESULT: 0x800A03EC Error. Perhaps 'sleep'ing a bit longer might help...

Categories

Resources