I found a code example online that purports to count the number of pages in a PDF file. However, I'm getting the error 'ToArray is not a member of 'String' on the following line:
Dim pdfMagicNumber() As Char = "0000".ToArray
I'm running VS 2010 on a Framework 2.0 project, on a machine running Windows 7 and IIS 7. I found one article that talked about IIS configuration as the culprit for this error, but my settings seem to be consistent with what they recommended.
Any ideas on this error?
Thanks!
Mike
ToArray is an extension method introduced in .NET 3.5 on IEnumerable<T>. It works in .NET 3.5+ when called on string, as string implements IEnumerable<char>.
However, string.ToCharArray() is available in all versions of .NET, and even when you're using .NET 3.5+, it will be more efficient than ToArray.
In other words, you want:
Dim pdfMagicNumber() As Char = "0000".ToCharArray
Related
I have opened a website project that has previously been developed in Visual Studio 2012 in 2015 RC. The project targets .net 3.5.
I have this interface defined:
Public Interface ICurrentStep
Property outerstep() As String
Property innerstep() As String
End Interface
I get the following build error for each property: "BC36716 Visual Basic 9.0 does not support auto-implemented properties."
I don't understand why Visual Studio 2012 is perfectly happy with this but 2015 is not. The website works fine under .net 3.5 in both xcopy and published versions.
I also don't understand how would I define the interface any other way. Could this be a 2015/Roslyn bug?
Targeting .net 4.0 does remove the problem but that's not an option for deployment at the moment due to some external dependencies. I presume that's because behind the scenes it's targeting a different compiler as per Is it possible to force Visual Studio 2010 to use Visual Basic 10?
In my case, using VS2015 Community, the real problem was a blank line between the property header and the Get method. See my screenshots below:
Before: (Error image)
After: (No error image)
This does indeed appear to be a bug in the Roslyn compiler. The compiler is running in an odd mode where its checking (but not really compiling) the code within App_Code - that code actually gets compiled when the site starts up.
Since it knows that you've set the code to run under v3.5, it assumes that the code will actually be compiled by the "v2.0" compiler, so it's effectively running the check/compile as if you've specified the /langversion flag as 9.
So, that's why the error message is talking about things not supported by Visual Basic 9. However, if you compile the code with real VB9 compiler, it of course compiles fine.
As evidence that the compiler is rather confused, I changed your sample to:
Public Interface ICurrentStep
Property outerstep() As String = "Hello"
Property innerstep() As String
End Interface
This should produce an error about not being allowed an initializer in an interface. However, instead of just two error messages stating "Visual Basic 9.0 does not support auto-implemented properties." we also get the error "Expanded Properties cannot be initialized.". But, this does not make sense:
there are situations in which you cannot use an auto-implemented property and must instead use standard, or expanded, property syntax.
That is, a single property can either be auto-implemented or expanded.
My recommendation would be to move as much code as possible out of App_Code - either just outside of it or into a different library. This will then mean that the code is actually compiled by the Roslyn compiler directly (and without the /langversion setting) and that you can actually start making using of modern VB features (you can still target v3.5 but use later language features)
In the alternative, you can leave the code in App_Code and choose to ignore the errors. If it's just two errors, that may be feasible in the short term.
I have a project that is in the process of moving to use VS2015 from VS2008. We need to support both environments in the short term so I have created VS015 .vbproj files that include the directive
9
in the PropertyGroup section of the file.
I was getting this error because there was a comment between the Property declaration and the Get clause.
For example
Private ReadOnly Property MemberNode() As XmlNode</br>
' This is the only place which locates the objMember node
Get
Return CreatePathAndNode(mnodMessage, "objData/colMember/objMember")
End Get
End Property
Moving the comment before the "Private Readonly" line removed the compiler error in VS2015.
This may seems trivial and OT, but if you're using Visual Studio Community 2015 and you're targeting .net 3.5 make sure the line continuation "_" has not been automatically removed.
VSC 2015 automatically removes the line continuation upon edit and there's no way to reinsert it back (I had to do it outside of VSC 2015). Furthermore the compiler gives you an error on that line but the editor does not underline it.
In my case (VS2015, ASP.NET app, VB.NET, .NET 4.6) I've solved it by removing the space between the procedure declaration and the Get.
The snippet below raises the "Visual Basic 12.0 does Not support ReadOnly auto-implemented properties."
Public ReadOnly Property TestProp() As Integer
Get
Return 0
End Get
End Property
The snippet below does not.
Public ReadOnly Property TestProp() As Integer
Get
Return 0
End Get
End Property
Public Interface ICurrentStep
Private _outerstep As String
Property outerstep() As String
Get
Return _outerstep
End Get
Set(ByVal value As String)
_outerstep = value
End Set
End Property
End Interface
In my case i had to upgrade the the .NET framework. It was on 2.0 and i upgraded it 4.0 after which i was able to add the assembly reference for
and the errors went away
In classic ASP, I am trying to create an ActiveX object. Basically, I am trying to create a Crystsal Reports Runtime object.
Dim oCR = CreateObject("CrystalDesignRunTime.Application")
I am getting "ActiveX cannot create object" error.
This works fine on another developer machine. And both developer machines have Windows 7 VB 6 EE with SP 6 and Crystal Reports Developer edition 13.0.
Help needed :-(
If this is classic ASP, with VBScript, then:
Dim oCR = CreateObject("CrystalDesignRunTime.Application")
... is definitely not going to work. This should be:
Dim oCR
Set oCR = CreateObject("CrystalDesignRunTime.Application")
As for the "ActiveX cannot create object" error, this is due to an installation failure of the Crystal Reports component. I would recommend you first try reinstalling the component. Failing that, look in the installation folder, and work out which file implements the ActiveX component (crtslv.dll ?). Then go to a command line and type:
regsvr32.exe "<component DLL file>"
I have a classic ASP application written many years ago that I'm trying to fix.
The following lines recently stopped working after w7 sp1 was applied.
set address = Server.CreateObject("ADOR.Recordset")
count = lo_connection.GetRecordset(sql,address,false, error)
Set RDF2 = Server.CreateObject("RDSServer.DataFactory")
Set teststring = RDF2.ConvertToString(address)
It fails on the last line there saying "Microsoft VBScript runtime error: Class doesn't support Automation"
A bit of searching found several articles like this one
http://blogs.technet.com/b/asiasupp/archive/2011/03/14/changes-in-mdac-adodb-com-components-in-windows-7-service-pack-1.aspx
that described the problem exactly. Where I am failing is that none of the suggested fixes seems to fix the problem. Any suggestions?
The solutions described in the link are not relevant here, since ASP is not early-bound - it uses OLE Automation. It might be worth re-registering the component which creates RDSServer.DataFactory objects (which is C:\Program Files\Common Files\system\msadc\msadcf.dll on my machines).
I looked up this object, and I found this Microsoft web page:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681447(v=vs.85).aspx
"This feature will be removed in a future version of Windows. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Applications that use RDS should migrate to WCF Data Service."
Doesn't sound too good.
I have a website I developed in VS 2008 targeting .net 3.5. It has worked well. I recently upgraded to VS 2010 and needed to make a few changes to the site. However, I'm receiving compile errors (haven't made any changes to the code yet--was just launching the site to make sure it worked ok). I get "Contains" is not a member of system.array. Everything I've read states that the contains method was added in .net 3.5, which I know to be correct because it was working in VS 2008. I've been targeting .net 3.5 in VS 2010, but it still isn't working. I also used linq quite a bit with linqkit to do dynamic queries and all of my linq queries were saying my queries weren't queryable (I don't have the actual error in front of me). Anyway, to fix that one, I had to import system.linq (I previously had system.data.linq and it was working fine). To reiterate, I haven't targeted my site to .net 4 in VS 2010, I've left it targeting .net 3.5.
I tried converting my arrays to arraylists since arraylists were still pulling up with a .contains method, but then it broke my linqkit queries when I ran it on the site.
Here is my linqkit query:
Dim str() As String = archlist.ToArray(GetType(String))
Dim str3 As New ArrayList
str3 = ArrayList.Adapter(str)
predicate = predicate.And(Function(l As CompatTesting) str3.Contains(l.application.cpuarchitecture))
Before, I didn't have the arraylist conversion, I just had str.contains and it worked great to generate a sql "in" statement. Now after using the code above, the site launches, but when I actually run the code, I get Method 'Boolean Contains(System.Object)' has no supported translation to SQL. I also tried upgrading my linqkit dll to the latest version but it didn't help.
My questions are, since I'm targeting the same .net 3.5 framework in 2010, why is it not allowing me to use array.contains anymore? Maybe if I can address that issue, it will fix my linqkit issue where it says "contains" has no supported translation to sql.
Any help would be appreciated. I don't want to revert back to vs 2008 just to fix my site...
Right click on project -> Open Property Pages (Shift+F4)
Set Target Framework to .NET Framework 3.5 then click OK and build project.
I’ve just enabled config transformations on a .NET 3.5 project in VS2010 RC after watching Scott Hanselman’s video on web deployment. Unfortunately every time I go to publish I now get the following error:
The "TransformXml" task failed
unexpectedly.
System.UriFormatException: Invalid
URI: The URI is empty. at
System.Uri.CreateThis(String uri,
Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at
Microsoft.Web.Publishing.Tasks.TransformXml.Execute()
at
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at
Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost
taskExecutionHost, TaskLoggingContext
taskLoggingContext, TaskHost taskHost,
ItemBucket bucket, TaskExecutionMode
howToExecuteTask, Boolean& taskResult)
If I take a brand new VS2010 web application which already has the config transformations by default I don’t have a problem so I suspect my issue is project related. Has anyone come across this before or have any ideas on a fix?
Looks like the answer was simple yet obscure; I had an app setting (a password), which contained a ">" symbol. I tried converting the app to .NET 4 then back to .NET 3.5 and everything ran fine as during the process the symbol had been escaped to ">". Never had a problem with this character until config transformations came along but at least the fix is now simple.
Edit: blogged about in a bit more detail: Visual Studio 2010 Config Transformations TransformXml task failure
FYI: my project was already targeting .NET 4.0, so I switched it to 3.5 and then back to 4.0 and it works that way as well.