Error Type 'MarshalAs' is not defined
I recently converted a project from VB2003 to VB2005. I am getting this error and I can't figure out why...
Type 'MarshalAs' is not defined
Here is an example of the code that is causing the error:
<StructLayout(LayoutKind.Sequential)>
FriendStructure VersionInfoDef
Dim SizeofVersionInfoAsByte
Dim BootVersionAs VersionDef
Dim OSVersionAs VersionDef
Dim NumOSExtensionsAsByte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=40)>Dim OSExt()AsByte
PublicSub Initialize()
ReDim OSExt(39)
EndSub
EndStructure
I have tried every Imports statement I can think of. Here is what I have now...
Imports System.Runtime.InteropServices
Imports System.Runtime.InteropServices.UnmanagedType
Imports System.Runtime.InteropServices.Marshal
Imports System.Runtime.InteropServices.StructLayoutAttributeI also notice that when I click on the error in the error list, it does not take me to the error even though it shows a line number with the error.
Thanks for your help..
Clark
[2776 byte] By [
csann] at [2008-2-6]
Wacko
Thanks for your reply. When I change my code to your code I get another error "Type 'Runtine.InteropServices.MarshalAs' is not defined. I am now getting this error on this structure instead of the previous error. It seems that Runtime.InteropServices is messed up.
Is something wrong with my installation of VB2005 or is this a bug?
Clark
I agree, doesn't sound like a bug. Somehow my VS studio environment does not know about MarshalAs.
Just a couple of last followup questions, wacko...I didn't totally understand what you were saying at the start of your first post....with respect to Imports.
Are you saying you have this imports statement in your program...
Imports Runtime.InteropServices.MarshalAs ?
When I try to enter that, there is no MarshalAs available after InteropServices. I only have Marshal and MarshalAsAttribute. Does your system behave this way? Is your system different than mine? I have tried imported both Marshal and MarshalAsAttribute....neither helps. Thanks again for taking the time to try to help me. Unless I can quickly find what is wrong with my system, I guess I will reinstall VS2005 on a clean machine and see what happens.
Clark
Intellisense is working the same for me too. The error happens when I try to compile. Since you can compile ok, it is clear that I will have to repair VS, reinstall VS, or kill my computer.... HA!
Thanks for your help!!!
Clark