I have a VB.NET project targeting framework 3.5 that references a dynamic DLL of compiled enums generated from a database. My project compiles and runs in Visual Studio 2012. I am beginning to upgrade my solutions to Visual Studio 2015 and ran in to a bunch of errors when I tried doing this project.
The two errors I get for just about every enum are
Operator '=' is not defined for types MyEnumType and MyEnumType
Field MyEnumType.Field has an invalid constant value
Viewing the definition of the enum meta data (which I can do in 2015 but not 2012) I see it being defined as
Enum EnumName as Object
Field1
Field2
End Enum
As you can see its appending As Object which I've never seen before. But that explains the operator = error because if it's an object than you would have to define an overloaded Equals operator.
I'm just seeing if anyone has any insight or know of anything in 2015 that would be causing this issue. I tried creating a new project an importing the .DLLs just to see if they worked at all in VS 2015. They work when referenced in C# but not in VB.NET. The .DLLs were written and compiled in VB.NET. S
For the time being I can still use 2012, but would like to upgrade to 2015 in the future and not have to rewrite a bunch of things.
EDIT:
Here is the (simplified) code that is being used to create the enum .DLL. An xml is being read with the Enum name and sql query used to generate the enum.
Dim myEnumBuilder As Emit.EnumBuilder
Dim myAppDomain as AppDomain
Dim myModuleBuilder As ModuleBuilder
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = EnumDll.Name
' Create a dynamic assembly.
myAssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Save, msOutputDirectoryPath)
' Create a dynamic module.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("Library." & EnumDll.Name, EnumDll.Name & ".dll")
' Creating a dynamic Enum.
myEnumBuilder = myModuleBuilder.DefineEnum(EnumDll.Name & "." & EnumName, TypeAttributes.Public, GetType(Int32))
Dim myFieldBuilder As FieldBuilder = myEnumBuilder.DefineLiteral(StrEnum, CInt(oReader(0)))
myEnumBuilder.CreateType()
myAssemblyBuilder.Save(EnumDll.Name & ".dll") 'save the dll
Related
I am trying to add the path and file name of files that throw exceptions (see image attached). My code works but Visual Studio Community Edition 2015 (VB.NET 4.6) reports "Variable 'FileName' is used before it is assigned a value...". Can anyone suggest how I can remove this issue, or whether this is ok to ignore? I am new to VB.NET and would be happy to reformat my code if there is a better way to do this.
Regards
George
use this:
Dim FileName as String = Nothing 'String.Empty 'C#: null
I have a problem trying to access data pulled as an array from a VB.NET DLL.
The DLL is registered correctly and working on the web server which is serving the asp classic pages.
I have tested the dll using a vb6 program and it retrieved the data that I expect.
Here is the code that I used for that.
Dim commItems
commItems = c.GetCommTypes
For i = LBound(commItems) To UBound(commItems)
Me.Label2.Caption = "Item: " & commItems(i).CommTypeID & " - " & commItems(i).CommTypeName
DoEvents
Sleep (1000)
Next
The error message I get is as follows, when trying to do the same thing is asp clasic
Microsoft VBScript runtime error '800a000d'
Type mismatch
/commtype.asp, line 13
Here is my asp code
Dim Core
Set Core = Server.Createobject("Advantage.Dealer.Email.CoreClassLibrary.CoreClass")
dim commItems
commItems = Core.GetCommTypes
For i = LBound(commItems) to UBound(commItems)
Response.Write commItems(i).CommTypeID
Next
I am not sure what I'm doing wrong but if i run this code
Dim Core
Set Core = Server.Createobject("Advantage.Dealer.Email.CoreClassLibrary.CoreClass")
dim commItems
commItems = Core.GetCommTypes
For i = LBound(commItems) to UBound(commItems)
Response.Write i
Next
I get
0123
So something is working, but not how I want it to.
Please be aware that it should return 4 rows of data
I would review the COM interface for the type returned in the array by the Core.GetCommTypes() method.
<InsiderKnowledge>
The Advantage.Dealer.Email.ModelClassLibrary.CommType class does not appear to have a COM interface declared.
This does not tally with your VB6 client successfully being able to consume its properties. Have you modified your assembly/assemblies between executing your VB6 and VB Script tests against them?
</InsiderKnowledge>
Ok so after a few more hours searching I found the solution I was looking for.
I found the answer here
http://bytes.com/topic/asp-classic/answers/167046-type-mismatch-error-when-accessing-array
Right at the bottom of the post.
Basically I was passing an array of my class type, and what I should have been doing is returning an array of System.Object type. I made some changes to my .net DLL so that rather than returning an array of the CommType Class it was returning an Array of System.Object
I have a WebMethod in a legacy service. This service is currently a .NET 3.5 built application (Visual Studio 2008):
<WebMethod(EnableSession:=True)> _
Public Function Login(ByVal username As String, ByVal password As Char()) As MyAppUser
Then from within a VB.NET MVC .NET 4.5 client (Visual Studio 2012) I try to access Login. (I've changed a few variable names to not use our internal naming - so don't mind any typos - the same code works in Visual Studio 2008 see below).
Dim MyWebService as WebService.WebServiceClass = New WebService.WebServiceClass()
....
Dim encryptedPassword As String = EncryptString(password)
Dim rights As WebService.MyAppUser = MyWebService.Login(user, encryptedPassword.ToCharArray())
The problem is that the Visual Studio 2012 compiler has a problem with the encryptedPassword.ToCharArray() - giving a
Error 1 Value of type '1-dimensional array of Char' cannot be converted to 'WebService.WebServiceClass.ArrayOfChar'.
Within the Reference.vb from my client reference:
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"), _
System.Runtime.Serialization.CollectionDataContractAttribute(Name:="ArrayOfChar", [Namespace]:="http://tempuri.org/", ItemName:="char"), _
System.SerializableAttribute()> _
Public Class ArrayOfChar
Inherits System.Collections.Generic.List(Of Char)
End Class
However, if I use the same code within a Windows .NET 3.5 web application (Visual Studio 2008) it compiles and works fine. I'd like to use ASP.NET MVC to make my life easier, but I can't seem to get over this little hurdle.
The error message indicated that encryptedPassword.ToCharArray() is returning an array when ArrayOfChar is the expected type, but I don't know why it worked in .NET 3.5.
Anyway, to get it to work, try to change this line:
Dim rights As WebService.MyAppUser = MyWebService.Login(user, encryptedPassword.ToCharArray())
to something like this:
Dim MyArrayOfChar As New ArrayOfChar
MyArrayOfChar.AddRange(encryptedPassword.ToCharArray())
Dim rights As WebService.MyAppUser = MyWebService.Login(user, MyArrayOfChar)
Note: I'm new to using Visual Studio and writing code outside of VB6 and VBA. Also, I've resolved my problem by using IO.File.
However, I really want to learn why this wouldn't work:
Dim FSO As New FileSystemObject
Dim FSOts As TextStream
FSOts = FSO.OpenTextFile(filepath1, IOMode.ForReading, True)
While FSOts.AtEndOfStream = False
temp = FSOts.ReadLine()
MsgBox(temp)
tempcollection.Add(temp)
End While
FSOts.Close()
It works on my computer, but for some reason it won't on others. I've used this object in a vb script before but in that situation the 2nd argument was 'ForReading' and was written in a different IDE (FEMAP) which referenced the 32bit scrrun.dll. In Visual Studio I noticed the scripting library is pointing to syswow64; I'm not sure if that makes any difference. All distributed sites run 64 bit OS and have this library. In any case I get an error 438 when I try to use:
FSOts = FSO.OpenTextFile(filepath1, IOMode.ForReading, True)
VS will not let me compile it with just 'ForReading'.
Again, I've used this object before in vb6 but the 2nd argument was not iomode.forreading but 'ForReading'. In that situation it worked fine on the same machines that are giving me problems (except for mine of course!).
We have created a workflow process as an SSIS package and would like to find a way of gaining access to this code so that through vb.net we can dynamically access and run that code. For example, we would like to change the data sources being used, or change the column mappings of existing packages and then execute them from a vb.net application. Please advise the best way to do this.
You will find some of your tasks easy, others not so much.
Generally speaking, you'll be interested in reading the Developers Guide to Integration Services. Of particular interest will be Building Packages Programmatically and Running and Managing Packages Programmatically.
For example, to run a package from VB.NET
Imports Microsoft.SqlServer.Dts.Runtime
Module Module1
Sub Main()
Dim pkgLocation As String
Dim pkg As New Package
Dim app As New Application
Dim pkgResults As DTSExecResult
pkgLocation = _
"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services" & _
"\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx"
pkg = app.LoadPackage(pkgLocation, Nothing)
pkgResults = pkg.Execute()
Console.WriteLine(pkgResults.ToString())
Console.ReadKey()
End Sub
End Module
To change the connection manager programmatically, it'd be the VB.NET equivalent of
ConnectionManager item = ep.Connections["MyConnectionManagerName"]
item.ConnectionString = #"Provider=SQLNCLI10.1;Data Source=Server1;Initial Catalog=ABC;Integrated Security=SSPI;";
Changing column mappings, that's where it's going to get interesting, for all definitions of the word interesting. I'm have a distilled example but it takes some work and you'll want to really understand the whole object model (and I hope you like COM). EzAPI might be of some assistance in that area.