have exception error when using Visa.Interop.ResourceManager in C# - c#

I'm using C# to control instrument(ex. function generator) but when using ResourceManager constructor some exception error occurs...
This is the exception System.Runtime.InteropServices.COMException'(System.Private.CoreLib.dll)
Could anyone help me with how to fix it?
I'm using Visual Studio and I've tried executing Visual Studio in administrator mode but it doesn't work either. hers's my code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Ivi.Visa;
using Ivi.Visa.FormattedIO;
using Ivi.Visa.Interop;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace upw_test1
{
public sealed partial class MainPage : Page
{
bool isconnected;
public MainPage()
{
this.InitializeComponent();
isconnected = false;
}
void Button_Click(Object sender, RoutedEventArgs e)
{
connection_result.Text = "Hello, " + Input_num.Text + "!";
if (!isconnected)
{
string srcAddress = "GPIB::";
srcAddress += Input_num.Text.ToString();
srcAddress += "::INSTR";
try
{
ResourceManager mngr = new ResourceManager();
catch (Exception exp)
{
//MessageBox.Show(exp.Message);
connection_result.Text = srcAddress + " connection fail ";
}
// GPIB address
}
}
}
}
below is the full stack trace of exception..

Related

How to handle the unit-test assembly load issue in C#

While loading assemblies from both x64/x86, I have got exception message as System.BadImageFormatException in my unit-test project.
Below is the code and screen shot of the exception I have got while debugging the test.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Example_Addin;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Microsoft.Office.Interop.Visio;
using Visio = Microsoft.Office.Interop.Visio;
namespace exampleProject
{
[TestClass]
public class exampleUnitTest1
{
[TestMethod]
public void Test_example()
{
try
{
Example exm_obj = new Example();
string file_path = "test.json";
string template_file = "template.vssx";
double height = 0.5;
double width = 0.5;
db_obj.read_data_shape_creation(#file_path, 0.5, 0.5, "F06", #template_file, "testing");
}
catch (Exception)
{
System.Diagnostics.Debug.WriteLine("Exception occour");
}
}
}
Here, I want to unit test my code with assembly dependencies, but after setting the assembly, I get the above snapped exception and code execution is halted. 
This issue happen due to my target framework for unit-test and my core-project are not matching. When I have correct both case it is working.

c# - geckodriver.exe selenium 3.8 not running nunit 3.9

I try to run Nunit_selenium automation in updated firefox version,
vs 13,
selenium webdriver 3.8.0
NUnit3TestAdapter.3.9.0
Selenium.Support.3.8.0
Selenium.WebDriverBackedSelenium.3.8.0
Firefox launched but driver url link not updated
issue :in firefox notrun_image
please find the below code :
.
.
.
.
.
.
.
/
namespace SanityTesting
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework.Constraints;
using NUnit.Framework;
using NUnit.Core.Extensions;
using System.Configuration;
using System.IO;
using System.Reflection;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium;
using Syncfusion.UnitTesting.Framework;
using OpenQA.Selenium.Remote;
using System.Threading;
using OpenQA.Selenium.Support.UI;
using System.Collections;
using OpenQA.Selenium.Firefox;
using System.Diagnostics;
using System.Globalization;
using System.Drawing;
using SanityTesting.AccordionFluent;
using System.Windows.Forms;
[TestFixture("Firefox")]
[TestDirectory("..\\..\\Accordion\\")]
public class EmberJS_Accordion : NUnitUtil
{
string activeBrowser;
public EmberJS_Accordion(string browser)
{
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\Drivers");
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
System.Environment.SetEnvironmentVariable("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver(service); // FirefoxDriver driver = new FirefoxDriver();
//driver = GetWebDriverForBrowser(browser);
//FirefoxProfile profile = new FirefoxProfile();
//profile.SetPreference("browser.startup.page", 0); // Empty start page
//profile.SetPreference("browser.startup.homepage_override.mstone", "ignore"); // Suppress the "What's new" page
// return new FirefoxDriver(profile);
activeBrowser = browser;
}
[TestFixtureTearDown]
public void quitDriver()
{
driver.Quit();
}
public void TakeAndCompareScreenshotByLocator(By Locator, string fileName)
{
IWebElement contents = driver.FindElementAfterClickable(Locator);
TakeAndCompareScreenshot(contents, fileName);
}
[Test, TestCaseSource(typeof(AccordionModel), "Sanity_Accordion")]
[Category("Sanity")]
[Component(Component.Accordion)]
public void EmberJS_Accordion_Sanity(string url, int time)
{
AutomationHelpers.GotoPage(driver, url);
driver.Navigate().Refresh();
driver.WaitForElementClickable(By.CssSelector(".e-acrdn"), time);
Thread.Sleep(200);
IWebElement contents = driver.FindElement(By.ClassName("cols-sample-area"));
TakeAndCompareScreenshot(contents);
}
}
change the following line of code,
FirefoxDriver driver = new FirefoxDriver(service);
to
driver = new FirefoxDriver(service);
I have doubt, is your NUnitUtil class have driver member variable. if yes, then above code may work.

EmguCV "The type initializer for 'Emgu.CV.CvInvoke' threw an exception"

I have got a problem when using EmguCV. Everytime I try to create SIFT or SURF detector I get exception "The type initializer for 'Emgu.CV.CvInvoke' threw an exception".
I've already: installed MSVCRT, copied OpenCV and Emgu dlls to the execution directory, added to solution OpenCV and Emgu dlls, added to solution Emgu.CV, Emgu.CV.GPU, Emgu.CV.ML, Emgu.CV.UI, Emgu.Util references.
Unfortunately I still got exception. I've tried to build SURFFeature example and it worked perfectly. It actually means that I make some mistake, but I can't find it... Please help...
Here's the code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Features2D;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.Util;
using Emgu.CV.GPU;
namespace blablabla
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Bitmap waveform_to_file = new Bitmap(2, 2);
//Emgu.CV.Features2D.SIFTDetector detector = new Emgu.CV.Features2D.SIFTDetector();//(0, 3, 0.04, 10, 1.6);//(400, true, 3, 4);//
SURFDetector surfCPU = new SURFDetector(500, false);//I got exception on these lines
Emgu.CV.Util.VectorOfKeyPoint keypoints = new Emgu.CV.Util.VectorOfKeyPoint();
Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> waveform_to_file_gray = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(waveform_to_file);
Emgu.CV.Features2D.ImageFeature<float>[] modKeyPointsArray = surfCPU/*detector*/.DetectFeatures(waveform_to_file_gray, null);
List<Emgu.CV.Features2D.ImageFeature<float>> modKeyPointsList = new List<Emgu.CV.Features2D.ImageFeature<float>>();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}
}
}
Solution explorer:
http://ifotos.pl/zobacz/4JPG_wwaerwh.jpg
bin/debug:
http://ifotos.pl/zobacz/3JPG_wwaereh.jpg

Error compiling delegate and dispatcher

I'm new to the threading world and trying to make my application works with threads. Here is what I got:
public static void ThreadProc()
{
Thread.Sleep(500);
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("SuperMMFofDoom", MemoryMappedFileRights.ReadWrite);
MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor(0, sizeof(double)*3 + sizeof(int) *2);
Image imgS = new Image();
ImageTrigger myMessage;
Mutex imgMutex = new Mutex(false, "imgMutex");
while (threadRunning)
{
imgMutex.WaitOne();
accessor.Read(0, out myMessage);
// [...]
Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(delegate()
{
// [...]
}),
new object[] { imgS, myMessage.performance }
);
imgMutex.ReleaseMutex();
}
}
This thing does compile when I comment all the Dispatcher.Invoke(). If I don't, I get an error about System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate, object) and it does not compile.
Any ideas?
I'm using VS2010 on Windows 7 Pro x64. This is a C# WPF project which also make use of some C++ DLLs also compiled in the same project. Finally, here is the header of the file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
using System.IO.MemoryMappedFiles;
using Common;
You should not be creating a new Action just casting your delegate as one:
Async:
Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)delegate()
{
});
Sync:
Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
});
Or if your not on a control or window:
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
});

Why doesn't my code-behind execute?

I am trying to output the value of x in the following request: http://localhost:4827/Default.aspx?x=123123
I am getting no output at all.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using MPads.Common;
using MPads.WebPatientPortal.Interfaces;
using MPads.WebPatientPortal.Presenters;
using MPads.BusinessLogic.Interfaces;
using MPads.Components.Interfaces;
using MPads.DataAccess;
using MPads.DataAccess.Interfaces;
using System.Text;
using System.Diagnostics;
namespace MPads.WebPatientPortal
{
public partial class Default : System.Web.UI.Page, IDefault
{
private DefaultPresenter _presenter;
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
_presenter = new DefaultPresenter();
var fields = Request.QueryString;
if (fields.Count > 0)
{
var x = Utilities.GetNvpValue(fields, "x").ToString();
Trace.Write(x);
}
}
public void loadAjaxContent(string content)
{
Page.RegisterStartupScript("myScript", " <script type=\"text/javascript\"> loadAjaxContent('" + content + "','POST',null); </script>");
}
public void DisplayMessage(string message)
{
}
}
}
Do you have your even handler set up in your ASPX?
Assuming that you do: Consider instead of Trace.Write(); using Response.Write();
Trace.Write(); writes to a trace listener (which you can have display at the bottom of your page).
Response.Write(); outputs text results directly to your page, not through a Trace Listener.
Use Glimpse to find out this, here's the link Glimpse-A client side Glimpse to your server

Categories

Resources