vb.net (4.0 framework) form not loading - vb.net

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.

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()

Error integrating MATLAB and Visual Basic

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.

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.

How to debug serialization error in tombstoned WP7 app

I am handling the current state of my WP7 app in the OnNavigatedFrom and To events so that if the app is tombstoned OR they navigate to a different page it saves the state to the inbuilt PhoneApplicationService state.
I have a simple ViewModel which I dump to the state to make life easier. When navigate to a different page within my app, the state is stored fine and restores fine (ie. I assume it is serializing at this point). However, when I tombstone the app (i.e. Start button) I am getting an unhandled error with serialization and the stacktrace is not giving me any clues as to why it is failing.
I have tried wrapping the actual call in a try catch block to try and see what is wrong but it doesn't help - it's something that the runtime is doing different on tombstoning with my object than when it just stores it between pages.
Here is my code:
protected override void OnNavigatedFrom(NavigationEventArgs args)
{
appService.State["TournamentViewModel"] = tournamentViewModel;
base.OnNavigatedFrom(args);
}
protected override void OnNavigatedTo(NavigationEventArgs args)
{
if (appService.State.ContainsKey("TournamentViewModel"))
{
tournamentViewModel = (TournamentViewModel)appService.State["TournamentViewModel"];
}
base.OnNavigatedTo(args);
}
This is the error that is generated - I really can't figure out where the problem is - how can I debug this better?
Exception Info:
Message: "SecurityException"
InnerException: "Could not evaluate expression"
StackTrace:
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateGetOnlyCollectionDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetGetOnlyCollectionDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.GetGetOnlyCollectionDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.XmlObjectSerializerContext.GetDataContractSkipValidation(Int32 typeId, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Runtime.Serialization.XmlFormatWriter.InternalSerialize(MethodInfo methodInfo, Object memberValue, Type memberType, Boolean writeXsiType, XmlObjectSerializerWriteContext context, XmlWriterDelegator xmlWriter)
at System.Runtime.Serialization.XmlFormatWriter.WriteValue(Type memberType, Object memberValue, Boolean writeXsiType, XmlObjectSerializerWriteContext context, XmlWriterDelegator xmlWriter)
at System.Runtime.Serialization.XmlFormatWriter.WriteMember(SerializingObject serObj, Int32 memberIndex, ClassDataContract derivedMostClassContract)
at System.Runtime.Serialization.XmlFormatWriter.WriteClass(CallStackElement`1 callStackElement)
at System.Runtime.Serialization.XmlFormatWriter.Serialize(XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.XmlFormatWriter.InitializeCallStack(XmlWriterDelegator xmlWriterDel, Object obj, XmlObjectSerializerWriteContext writeContext, DataContract contract)
at System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(Stream stream, Object graph)
at Microsoft.Phone.Shell.StreamPersister.Serialize(IDictionary`2 dictionary, IEnumerable`1 knownTypes)
at Microsoft.Phone.Shell.StreamPersister.Save(ShellPageManager shellPageManager, String key, IDictionary`2 dictionary, IEnumerable`1 knownTypes)
at Microsoft.Phone.Shell.PhoneApplicationService.FireDeactivated()
at Microsoft.Phone.Execution.NativeEmInterop.FireOnPause()
Update: By trial and error I found the problem to be the AppBar, which does not seem to be serializable. I marked it with [IgnoreDataMember] and it now throws a more meaningful error on a different problem. I would still like to know if there are any easy ways of catching this info...
Rodney,
My understanding is that when you put an object in one of the two State Dictionaries (the one off of PhoneApplicationPage and the other off of PhoneApplicationServices) it does not immediately serialize or deserialize.
If you use the Page.State to store data, it serializes your state bag when you leave the page, and deserializes when you return to the page (rather than when you add or read an object from the state bag).
If you use the PhoneApplicationService.State, serialization happens when you tombstone and deserialization when the application is re-activated (though I'm not sure if this is tied to the PhoneApplicationService.Activated event or not).
Page.State, by the way, doesn't allow sharing data between pages. Saving to PhoneApplicationService.State does allow you to do so.
IsolatedStorage.AppSettings seems to handle deserialization problems silently, so I'm not sure when that happens. Serialization, however, occurs when you call Save().
James
Well, how does your ViewModel express the way in which it's serializable? Personally I tend to try to steer clear of potentially-intricate serialization: one fairly simple option is to give your ViewModel the ability to explicitly convert itself to/from XML, and then perform that step manually yourself, saving an XDocument (or its string representation) in the application state. That way it's easy to debug the serialization step, see the exact XML being generated etc.
Of course, the use of XML here is incidental - if you can easily put everything in a CSV string, that would be fine too. Anything that you can easily inspect in terms of the serialized form before putting in application state.
I realise this is side-stepping some of the supposed benefits of the "automatic" serialization, but I've run into enough hard-to-diagnose problems with automatic serialization of arbitrary objects that I don't think the benefits outweigh the drawbacks.