System.InvalidOperationException on Sample Code - vb.net

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

Related

Exception has been thrown by the target of an invocation - vb.net

I have an issue where I am receiving the error, "Exception has been thrown by the target of an invocation. I have the new keyword in place. I made sure the ReportsData_Employee.COATSEndAssignmentDataTable existed.
Imports System.Windows.Forms
Imports Advance.Extensions.Reporting
Imports CrystalDecisions.Shared
Imports Advance.Common.Reporting
Imports System.IO
Public Class Activity_EndAssignmentTool
ReadOnly _dt As New DataTable
Dim _dts As New DataTable
Dim _bldts As New DataTable
Dim _xml_file_name_creation As String
'// This is the line that is causing the error ============
ReadOnly _xml_datatable As ReportsData_Employee.COATSEndAssignmentDataTable = New ReportsData_Employee.COATSEndAssignmentDataTable()
'//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
======================================================================================
System.Reflection.TargetInvocationException was caught
HResult=-2146232828
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName)
at Advance.Extensions.Activities.Activity_Form.GetActivityForm(String className) in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Forms\Activity_Form.vb:line 126
at Advance.Extensions.Activities.Activity_Form.SetActivityClass() in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Forms\Activity_Form.vb:line 60
InnerException: System.NullReferenceException
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Advance.Extensions.Activities
StackTrace:
at Advance.Extensions.Activities.Activity_EndAssignmentTool.InitializeComponent() in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Activity_Forms\Activity_EndAssignmentTool.Designer.vb:line 479
at Advance.Extensions.Activities.Activity_EndAssignmentTool..ctor() in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Activity_Forms\Activity_EndAssignmentTool.vb:line 12
InnerException:
Can someone name some other reasons why I could be getting this error? I have looked at multiple links but a lot of the answers don't apply in my situation.
"Exception has been thrown by the target of an invocation" error (mscorlib)
FYI I have tried ReadOnly _xml_datatable as New ReportsData_Employee.COATSEndASsignmentDataTable() and there was still an issue.
Any help is appreciated. Let me know if there is any other information you need.
Thanks.
You haven't initialized object properly. Here...
ReadOnly _xml_datatable As ReportsData_Employee.COATSEndAssignmentDataTable = New ReportsData_Employee.COATSEndAssignmentDataTable()
Should be
Private ReadOnly _xml_datatable As New ReportsData_Employee.COATSEndAssignmentDataTable()
Your real issue is
InnerException: System.NullReferenceException
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Advance.Extensions.Activities
You need to look into constructor of COATSEndAssignmentDataTable. you have NullReferenceException in there. These two lines tell you exact location
at Advance.Extensions.Activities.Activity_EndAssignmentTool.InitializeComponent()
in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Activity_Forms\Activity_EndAssignmentTool.Designer.vb:line 479
at Advance.Extensions.Activities.Activity_EndAssignmentTool..ctor()
in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Activity_Forms\Activity_EndAssignmentTool.vb:line 12

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.

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.

CannotCreateCustomizationDomainException: Customization could not be loaded because the application domain could not be created

I'm trying to run an Excel 2007 VSTO 3.0 addin we've created. However since installing the ION Trading MarketView Excel Plug-in our add-in no longer seems to load properly and fails with the following error:
Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateCustomizationDomainException: Customization could not be loaded because the application domain could not be created. ---> System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.LoadMafPipeline(AppDomain newDomain, IntPtr hostServiceProvider, AddInInformation info, EntryPoints requestedEntryPoints, OfficeApp officeApplication, OfficeVersion officeVersion, IntPtr& executor)
at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.CreateCustomizationDomainInternal(String solutionLocation, String manifestName, String documentName, Boolean showUIDuringDeployment, IntPtr hostServiceProvider, IntPtr& executor)
--- End of inner exception stack trace ---
Does anyone have any idea what could be causing this? Any pointers for how I could investigate further?
Thanks,
Tom
Here are some tips you may find on web, in order to fix the problem:
Reinstall VSTOR
Disable other add-ins
Install framework 3.5 sp1
Fix error in the security configuration on the computer that is running the Visual Studio Tools for Office solution
Modify/Disable custom rule of a company's virus software, blocking the .net framework ability to create the 'shadow copy' version of the vsto .dll.
Turn on .NET programmability support http://sqlblog.com/blogs/davide_mauri/archive/2010/07/30/powerpivot-not-visibile-in-excel.aspx
Move the entire solution to .NET 4.0

How to configure NHibernate class mapping from IronPython?

I try to use NHibernate from IronPython. I have copied the NHibernate dependencies to my C:\Users\shamel\python\HelloPy\libs directory.
I have this IronPython code:
import sys
sys.path.append("C:\Users\shamel\python\HelloPy\libs")
import clr
clr.AddReference("NHibernate")
clr.AddReference("LinFu.DynamicProxy")
clr.AddReference("NHibernate.ByteCode.LinFu")
from Entities.Entity import Customer
from NHibernate.Cfg import Configuration
configuration = Configuration();
configuration.Configure("PocoLib.cfg.xml");
configuration.AddXmlFile("Customer.hbm.xml");
factory = configuration.BuildSessionFactory();
My entity classes are defined in Entity.py in the Entity package. That explains the from Entities.Entity import Customer.
Here is what my Customer.hbm.xml file look like
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Entities"
namespace="Entities">
<class name="Customer" lazy="false">
...
</class>
The program fails on the configuration.AddXmlFile("Customer.hbm.xml"); line:
configuration.AddXmlFile("Customer.hbm.xml");
StandardError: Could not compile the mapping document: Customer.hbm.xml
ERROR: Module: nhtests could not be imported.
I suppose NHibernate is not able to resolve the assembly and namespace specified in the hibernate-mapping header. (The problem is not that the xml file is not found; I tried with a name that does not exist and I get a different error)
Any help will be greatly appreciated.
Sly
EDIT: 27 Dec 2009: Here is the stack trace. I think it confirms that NHibernate is not able to find my types.
*** Outer ***
MappingException
persistent class Entities.Customer, Entities not found
at Microsoft.Scripting.Actions.Calls.MethodCandidate.Caller.CallWithInstance(Object[] args, Boolean& shouldOptimize)
at IronPython.Runtime.Types.BuiltinFunction.BuiltinMethodCaller`2.Call1(CallSite site, CodeContext context, TFuncType func, T0 arg0)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.Scripting.Utils.InvokeHelper`6.Invoke(Object arg0, Object arg1, Object arg2, Object arg3, Object arg4)
at Microsoft.Scripting.Utils.ReflectedCaller.Invoke(Object[] args)
at Microsoft.Scripting.Interpreter.CallInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
*** Inner ***
MappingException
persistent class Entities.Customer, Entities not found
at NHibernate.Cfg.XmlHbmBinding.Binder.ClassForFullNameChecked(String fullName, String errorMessage)
at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindClass(XmlNode node, IDecoratable classMapping, PersistentClass model, IDictionary`2 inheritedMetas)
at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema, IDictionary`2 inheritedMetas)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode parentNode, IDictionary`2 inheritedMetas)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node)
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
*** Inner Inner ***
FileNotFoundException
Could not load file or assembly 'Entities' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName name, Boolean throwOnError)
at NHibernate.Util.ReflectHelper.ClassForName(String name)
at NHibernate.Cfg.XmlHbmBinding.Binder.ClassForFullNameChecked(String fullName, String errorMessage)
EDIT 29 Dec 2009 :
Even after I solve the namespace/assembly name issue, I don't think Nhibernate will be able to save/load my Python entities. As far as a now understand, when a Python instance is passed to a statically typed library (such as NHibernate), that library does not see its members. So Nhibernate will not find any property on my type because those properties are not visible to statically typed libraries. In order for this to work, NHibernate would have to support DLR integration, possibly using the C# 4.0 Dynamic keyword. To be continued...
It is not possible to use NHibernate from IronPython on entities defines in IronPython.