Error integrating MATLAB and Visual Basic - vb.net

The program is simple, it just adds the two number. Here's my matlab function that I created and built in .NET Assembly
function out = addMe(a,b)
out = a+b;
end
I then use the NE builder toolbox to generate a .NET component: http://imagizer.imageshack.us/v2/800x600q90/823/f77h.jpg
Imports Add
Public Class Form1
Dim a As Integer = 5
Dim b As Integer = 10
Dim res
Dim addme As New AddClass
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
res = addme.addMe(a, b)
TextBox1.Text = res
End Sub
End Class
But when I run the program, I'm getting this error:
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=An error occurred creating the form. See Exception.InnerException for details. The error is: Could not load type 'Add.AddClass' from assembly 'Add, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Source=Add
StackTrace:
at Add.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at Add.My.MyProject.MyForms.get_Form1()
at Add.My.MyApplication.OnCreateMainForm() in c:\users\elvin gentiles\documents\visual studio 2013\Projects\Add\Add\My Project\Application.Designer.vb:line 35
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Add.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.TypeLoadException
HResult=-2146233054
Message=Could not load type 'Add.AddClass' from assembly 'Add, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Source=Add
TypeName=Add.AddClass
StackTrace:
at Add.Form1..ctor()
InnerException:

You need to add required MatLab assembilies in your .NET application to run MatLab function.
Follow this link, I created that might give you some idea about adding Matlab assemblies:
http://www.youtube.com/watch?v=V-HmKmnsK88 (Part 2)
http://www.youtube.com/watch?v=gYJ7Q4liNYw (Part 1)
Hope this helps.

Related

How to add to a listbox from another thread (multithreading) in vb.net

So I have multiple threads running in vb.net. I need to know, how does one add to a listbox that was "created in a different thread"? I can't seem to get past this error!
Exact Error:
System.InvalidOperationException occurred
HResult=0x80131509
Message=Cross-thread operation not valid: Control 'ListBox2' accessed from a thread other than the thread it was created on.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.ListBox.NativeAdd(Object item)
at System.Windows.Forms.ListBox.ObjectCollection.AddInternal(Object item)
at System.Windows.Forms.ListBox.ObjectCollection.Add(Object item)
at SuperBC_Check_Pro.Form1.IncluBC(String username, String membershipType) in C:\Users\Owner\documents\visual studio 2017\Projects\SuperBC-Check Pro\SuperBC-Check Pro\Form1.vb:line 64
at SuperBC_Check_Pro.Form1.CheckBCMembership() in C:\Users\Owner\documents\visual studio 2017\Projects\SuperBC-Check Pro\SuperBC-Check Pro\Form1.vb:line 92
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
What do you guys suggest I go about fixing such an error?

System.InvalidOperationException on Sample Code

I am using some existing sample code given to me from FedEx.com for tracking packages. However, I cannot get it to work for the life of me. Would anyone know what the following means:
System.InvalidOperationException was unhandled
Message="Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert
type 'AddressValidationWebServiceClient.AddressValidationWebReference.ParsedElement'
to 'AddressValidationWebServiceClient.AddressValidationWebReference.ParsedElement[]' "
Source="System.Xml"
StackTrace:
at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
at AddressValidationWebServiceClient.AddressValidationWebReference.AddressValidationService..ctor() in C:\Documents and Settings\jessey\My Documents\Visual Studio 2008\Projects\AddressValidationWebServiceClient\Web References\AddressValidationWebReference\Reference.vb:line 40
at AddressValidationWebServiceClient.AddressValidationWebServiceClient.Main() in C:\Documents and Settings\jessey\My Documents\Visual Studio 2008\Projects\AddressValidationWebServiceClient\AddressValidationWebServiceClient.vb:line 28
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
The offending line of code is:
Dim service As AddressValidationService = New AddressValidationService()

IIS 7.5 w3wp process randomly throws ThreadInterruptedException

I'm working on a MVC4 application. It runs on IIS 7.5.7600. At random time intervals w3wp process throws ThreadInterruptedException with this trace. I have no idea where or why this happens. Does anyone out there have any idea?
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>/LM/W3SVC/1/ROOT/FiscalPower-188-130247532528202235</AppDomain><Exception><ExceptionType>System.Threading.ThreadInterruptedException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Thread was interrupted from a waiting state.</Message><StackTrace> at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Data.ProviderBase.DbConnectionPool.CleanupCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()</StackTrace><ExceptionString>System.Threading.ThreadInterruptedException: Thread was interrupted from a waiting state.
at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Data.ProviderBase.DbConnectionPool.CleanupCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()</ExceptionString></Exception></TraceRecord>
It is when the tcp connection has been closed before your code has been able to finish to return data. IE: your user pressed F5.

vb.net (4.0 framework) form not loading

hoping someone might be able to shine some light on this issue.
I have a form in vb.net (using VS2010, .net 4.0 framework) that will not load, but instead errors out in the variable declarations. I have the following two lines in my declarations
Dim rpRBuilders As New rpRBuilder_2010.rp_RBuilder
Public CR As New ReportDocument
Now, when I place my breakpoints on each line, it breaks at the first line, but errors out upon processing "Public CR As New ReportDocument" and receive a generic error screen:
I have downloaded and imported all crystal report libraries for VS2010, and am using versions 13.0.2000.0 in my project.
The exception detail provided isn't especially helpful to me, but one of you may be able to understand it better than I:
System.InvalidOperationException was unhandled
Message=An error occurred creating the form. See Exception.InnerException for
details. The error is: Invalid ServicedComponent-derived classes were found in the
assembly.
(Classes must be public, concrete, have a public default constructor, and meet all
other ComVisibility requirements)
Source=ReportBuilder2010
StackTrace:
at ReportBuilder2010.My.MyProject.MyForms.Create__Instance__[T](T Instance) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at ReportBuilder2010.My.MyProject.MyForms.get_frmReports()
at ReportBuilder2010.frmReports.Main() in C:\To Back Up\Repository\Report Builder
2010\ReportBuilder2010\ReportBuilder2010\frmReports.Designer.vb:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.EnterpriseServices.RegistrationException
Message=Invalid ServicedComponent-derived classes were found in the assembly.
(Classes must be public, concrete, have a public default constructor, and meet all
other ComVisibility requirements)
Source=System.EnterpriseServices
StackTrace:
at System.EnterpriseServices.RegistrationThreadWrapper.PropInstallResult()
at
System.EnterpriseServices.RegistrationHelper.InstallAssemblyFromConfig
(RegistrationConfig& regConfig)
at System.EnterpriseServices.RegistrationHelper.InstallAssembly(String
assembly, String& application, String partition, String& tlb, InstallationFlags
installFlags)
at System.EnterpriseServices.RegistrationHelper.System.EnterpriseServices.
Thunk.IThunkInstallation.DefaultInstall(String asm)
at System.EnterpriseServices.Thunk.Proxy.RegisterAssembly(Assembly assembly)
at System.EnterpriseServices.Thunk.Proxy.LazyRegister(Guid id, Type
serverType, Boolean checkCache)
at System.EnterpriseServices.Thunk.Proxy.CoCreateObject(Type serverType,
Boolean bQuerySCInfo, Boolean& bIsAnotherProcess, String& uri)
at System.EnterpriseServices.ServicedComponentProxyAttribute.
CreateInstance(Type serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK
(RuntimeType serverType, Object[] props, Boolean bNewObj)
at ReportBuilder2010.frmReports..ctor() in C:\To Back Up\Repository\Report
Builder 2010\ReportBuilder2010\ReportBuilder2010\frmReports.vb:line 27
Thank you all in advance for your help, I can provide more details if needed.

Null reference exception using HttpClient with async/await in MVC 4 application

I am using HttpClient to call a REST API. HttpClient.GetAsync method works fine if I call it from a test project. But calling HttpClient.GetAsync() from an MVC 4 application throws an unhandled object reference not set exception with the following stack trace:
at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state)
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(Object state)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.AwaitTaskContinuation.<ThrowAsyncIfNecessary>b__1(Object s)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
I am running .NET Framework 4.5. Any idea how to fix it.