windows forms load report failed - vb.net

I am developing a Windows Form application using Visual Studio 2010 and framework 4.0. I have a number of reports that this application will use.
My solution is divided up into folders so that I can keep my files organized. I have a process in one folder that is trying to load the Crystal Report located in another folder.
When I try to load the report file, I get an error "Load Report Failed". A Google search says it either cannot find the file or the folder does not have permission to access it. Since this is a WinForms application, I do not think the permissions have anything to do with the error since this application and all its folders are included in the overall assembly. I have tried - in debug mode - to use difference file naming to include the folder using just about every combination I can think of but to no avail.
I cannot see why the error occurs. Any clues?
Dim rpt As New ReportDocument
With rpt
.Load("Form1500_0212.rpt")
.SetParameterValue(0, bID)
.SetParameterValue(1, ProviderID)
.VerifyDatabase()
End With
Dim frm As New frmViewReport()
frm.ShowDialog()

there are a lot of possibilities why this is happening..
first, try to specify the full filepath for this line of code
.Load("fullfilepath")
'e.g., "C:\EmailSys-Phase2\Code\EmailSystem1\xtalReport.rpt"
second, have you installed the runtimes for crystal reports? You can get it here
third, have you tried adding this on your app.config file?
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
fourth, try checking if your target framework is set to .NET Framework 4.0 AND NOT .NET Framework 4.0 Client Profile (I think you're okay with this step already)

I also discovered that you need to change the property for "Copy to Output Directory" needs to be set to "Copy Always" so that the report definition is available in the executable path. Now my code works with this
With rpt
.Load(Application.StartupPath + "\Form1500_0212.rpt")
.SetParameterValue(0, bID)
.SetParameterValue(1, ProviderID)
End With

Related

setup file failing debugging enabled

I have used Setup Project before with no issue the project did not have SQLite DB as a dependency
I am now trying to make a EXE or msi file for a project that has SQLite included as System.Data.SQLite.Core and the project is a WinForms with a WPF TextBox with this code below
Public Sub LoadTB()
Dim tb As Windows.Controls.TextBox = New Windows.Controls.TextBox()
ElementHost1.Child = tb
tb.SpellCheck.IsEnabled = True
AddHandler tb.TextChanged, AddressOf tb_TextChanged
tb.TextWrapping = Windows.TextWrapping.Wrap
tb.AcceptsReturn = CBool("True")
End Sub
Here is part of the file file
************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139'
A picture is worth a 1000 words
Here is the issue the System.Data.SQLite.dll in the project is version 1.0.133.0
The NuGet package System.Data.SQLite.Core is version 1.0.113.1
Question what do I change and Where do I change it
YES I have tried using System.Data.SQLite from NuGet NO Luck
After continuing to try and use the Setup Project in Visual Studio 2019 to create both EXE & MSI installers I have found a FIX to the issue Exception Text ERROR as explained in my question above
Create your Setup Project with the Normal Steps
After you navigate to the Setup folder and open the Debug folder and click the setup.exe file the next Step is as follows YES it is Odd and not ideal compared to using Inno Setup but if you do not want to learn how to use Inno Setup this works. Why it is necessary is beyond me
OK now navigate to the folder where your application EXE file is located
Add the following two folders from your project X64 & x86 folders they are in the source folder for VS 2019 for your project
One more detail DO NOT use the desktop icon created by setup.exe
Click the AppName.exe in the Application Folder to run the application
Yes It is a different app than the app in the question
Here are two screen shots that add more clarity to the issue
Partial answer I say Partial because I do not know how to implement all the steps
So If someone would be kind enough to explain how to apply this fix that would be nice
As well if this is not the ideal way to correct the issue please comment
The ERROR as I see it is that SQLite.Interop.dll v 1.0.109.0 under
C:\Program.Files(x86)\MicrosoftVisualStudio\2019\Community\Common7\IDE\PrivateAssemblies\x86
as well as x64 and System,Data.SQLite.Core is v 1.0.113.0 Do NOT match
So applying the steps as described in this SO Post should solve the problem?
LINK to SO Post

Compiling Windows Form app created in VS2017 using VBC.exe?

I need to be able to program from Visual Studio but also from a usb key on computers without admin access.
To reach this goal I have used the following tutorials
VB.Net Programming Using Notepad And Command Prompt (Part I)
Tutorial(VB.Net) Creating Windows Form App Using Notepad+CommandPrompt
Now this works great without only one issue, it is hard to edit with visual studio. Intellisense doesn't work too good due to lacking files such as App.config and whatever is in the "My Project" subfolder.
So I decided to instead try to start from a VS2017 project and compile that using only vbc.exe and resgen.exe
Here is my attempt so far.
First I created a new project.
I chose a Windows Form project although the application I want to make will probably start in a "Sub Main" and run an "ApplicationContext" class instead of a form. I tried Console Application, however I find the console window annoying. I can hide the console window easily but it still flashes on startup. WPF looks too new and hard to use for now. A Windows Service might requite admin privileges to run and I'm not sure what an empty project really is.
So I create a Windows Form project
Next up I made the first two changes
I disabled the application framework.
It does something about the My namespace. It makes manual compiling much harder for some reasons. Also I changed the target .net framework to version 4.
This version is because I mostly find version "v4.0.30319" of the .net framework is installed so later version might not work.
Now, I save all that and try to build. An empty form window appears, this works so far from within visual studio at least.
For compiling I have a rudimentary .bat script.
I copy the freely available resgen.exe file to the "My Project" folder.
The code from compile.bat
path=%path%;c:\windows\microsoft.net\framework\v4.0.30319
cd "My Project"
resgen /compile Resources.resx,..\bin\debug\Resources.resources
cd ..
VBC /OUT:bin\Debug\app.exe /resource:"bin\debug\*.resources" /imports:System.Data,System.Deployment,System.Drawing,System.Windows.Forms,System.Xml,System.Xml.Linq,System.Data.DataSetExtensions,System.Collections,System.Collections.Generic,System.Data,System.Drawing,System.Diagnostics,System.Windows.Forms,System.Linq,System.Xml.Linq,System.Threading.Tasks /T:exe *.vb "My Project\*.vb"
pause
Some explanations,
First running this script with recompile the resource file and then compile the executable.
It will include all of the *.vb files as well as the resource file.
The following files are ignored so far
App.config
WindowsApp2.vbproj
My Project\Application.myapp
My Project\Settings.settings
Now the long list of imports is from the vbproj file.
It does not currently updates itself when you add more references in visual studio. A future version of this bat file will be made using vbscript and should extract and auto-add the imports/reference but not there yet.
Now what happens when you run this ?
It does not work with 3 errors as follows :
First it does not respect the defined startup object
This object is defined in the .vbproj file as follows
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<StartupObject>WindowsApp2.Form1</StartupObject>
</PropertyGroup>
</Project>
This section is not taken into account by vbc.exe yet so it appears to default to using a Sub Main and gives this first error.
vbc : error BC30420: 'Sub Main' was not found in 'app'.
Second and third errors as follows
C:\defaultpath\Visual Studio 2017\Projects\WindowsApp2\WindowsApp2\My
Project\Settings.Designer.vb(67) : error BC30002: Type 'WindowsApp2.My.MySetting
s' is not defined.
Friend ReadOnly Property Settings() As Global.WindowsApp2.My.MySettings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\defaultpath\Visual Studio 2017\Projects\WindowsApp2\WindowsApp2\My
Project\Settings.Designer.vb(69) : error BC30456: 'WindowsApp2' is not a member
of '<Default>'.
Return Global.WindowsApp2.My.MySettings.Default
Both of these errors are related somehow to the Root Namespace configuration
This is declared in the .vbproj file but not currently taken into account by the compile.bat file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<RootNamespace>WindowsApp2</RootNamespace>
</PropertyGroup>
</Project>
In the document Visual Basic Compiler Options Listed Alphabetically
The option /rootnamespace is defined to "Specifies a namespace for all type declarations."
So I add the /rootnamespace:WindowsApp2 to my compile.bat file and both previous issues listed above are solved.
Lastly, to fix the Sub Main issue and instead use "WindowsApp2.Form1" as defined in the .vbproj file
The /main command seems to fit the bill for this, so I add /main:WindowsApp2.Form1 to the command line.
Following some last minute changes to .resource file handling here is the latest compile.bat
path=%path%;c:\windows\microsoft.net\framework\v4.0.30319
cd "My Project"
resgen Resources.resx
cd ..
VBC /OUT:bin\Debug\app.exe /main:WindowsApp2.Form1 /rootnamespace:WindowsApp2 /resource:"My Project\*.resources" /imports:System.Data,System.Deployment,System.Drawing,System.Windows.Forms,System.Xml,System.Xml.Linq,System.Data.DataSetExtensions,System.Collections,System.Collections.Generic,System.Data,System.Drawing,System.Diagnostics,System.Windows.Forms,System.Linq,System.Xml.Linq,System.Threading.Tasks /T:exe *.vb "My Project\*.vb"
pause
This compiles an executable without errors.
I run it and Form1 appears, unfortunately the Console window also appears !
So it seems I still have a Console App and not a Windows Form App
This is resolved by modifying the /T parameter defined as /target from exe to winexe
Final compile.bat
path=%path%;c:\windows\microsoft.net\framework\v4.0.30319
cd "My Project"
resgen Resources.resx
cd ..
VBC /OUT:bin\Debug\app.exe /main:WindowsApp2.Form1 /rootnamespace:WindowsApp2 /resource:"My Project\Resources.resources" /imports:System.Data,System.Deployment,System.Drawing,System.Windows.Forms,System.Xml,System.Xml.Linq,System.Data.DataSetExtensions,System.Collections,System.Collections.Generic,System.Data,System.Drawing,System.Diagnostics,System.Windows.Forms,System.Linq,System.Xml.Linq,System.Threading.Tasks /T:winexe *.vb "My Project\*.vb"
pause
If anyone has any comments or suggestions I would gladly hear them.
I started writing this as a question but I resolved my issues in the course of writing this question.
If there is an easier way to do this please let me know.
In the mean time I hope this can be useful to someone else on the same path as I.
Bye !

Reference VB.NET DLL in Kofax Document Validation Script

We are working on a validation script for Kofax Capture 9.0 / 10.0 in VB.NET 3.5.
We know how to create a script using the Admin Module, and how to get it operational.
The problem is that we need to reference a dll, located on a remote machine. (GAC is no option) This dll holds abstract classes we need in each validation script.
Even when putting the dlls locally (copy local), the Validation Module (index.exe) immediately throws the "cannot find reference" exception, even though the project compiled perfectly.
I guess the basic question comes down to: where do we put the dlls, in order for the Validation Module to find them?
The simple answer is to put the dll in the same folder as the application because this is one of the places which .NET will probe when trying to find it. The Validation module is run from the Capture bin directory which will be something like "C:\Program Files (x86)\Kofax\CaptureSS\ServLib\Bin\". This would need to be done on each client using Validation.
If you have a more complicated scenario, you could look implementing the AppDomain.AssemblyResolve Event and using Assembly.LoadFile to get the assembly from a custom location, but the using the bin path is less complicated.
If you end up having further trouble, you can troubleshoot by using the Assembly Binding Log Viewer (Fuslogvw.exe) which can tell you more details about why the assembly failed to load and where .NET tried to search for it. Assembly loading can fail for reasons other than just the path.
For more detail on how .NET loads assemblies, see the following:
How the Runtime Locates Assemblies
Locating the Assembly through Codebases or Probing
We found a solution: add all library files as "links" to the project. (Add --> Existing File --> small arrow next to "Add" --> Add as Link)
This ensures the files are compiled when you build the project. The Kofax Validation Module can now find the files, whereas when referencing the file, it could not. Why it could not, remains a mystery...

Getting rid of App.exe.config

I am working on a vb.net application that uses SQLite and since it was compiled against the version 2 of the .net framework, i added this line to my config file
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
My final objective for the application is to make it a standalone, so not a single file except the exe (well the application will generate a file for the database, but my point is i want the user to only download 1 single file).
And i noticed that when i build it, the config file is always copied, and if i run the application without the config file, i would get the uncaught exception "legacy" error..
Is there any way to either include that config during runtime? or perhaps catch some type of exception to prevent that dialog from showing up and scaring the user (i know this probably not the best approach)
I have searched and found other similar problems on SO but none of the questions i found got to a solution that worked for me so i would appreciate your help.
While it is possible to set the legacy runtime policy at runtime, I would recommend deploying as an installer.
well the application will generate a file for the database, but my point is i want the user to only download 1 single file
They could download your installer, which could take care of setting up everything correctly. This is likely to be required in any case, as SQLite will need its own DLLs as well as your .exe to be there in the deployment.

Weird problem with Visual Studio 2008 website reference

I'm trying to add a reference to the GAC version of System.Xml in a Visual Studio 2008 web site project. I right-click the project icon in the Solution Explorer, and click Property Pages. Under the References tree option, I click the 'Add' button on the right. I navigate to System.Xml in the .NET tab, and double click it (the Path it lists for System.Xml, C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.XML.dll, DOES exist). The dialog disappears, but... System.Xml does not get added as a reference! The list just stays the same.
I tried adding another .NET reference just to make sure others could be added OK, I added System.Web.RegularExpressions and it added fine. What on earth could be causing it not to add System.Xml?
Try to edit your vbproj file, and add
<Reference Include="System.Xml" />
I just created a ASP.NET Website with default language C# & .NET 2.0 as the target. I also observed that even if you try to add a reference to System.XML, you will not find one in the project proprieties page.
As far it goes for me, its as designed.
By default you can access all the default .NET namespaces (in your target version) by just adding "using NAMESPACE_NAME;" in you code behind.(System (& the sub namespaces like XML etc). ASP, Microsoft & MS) Only when you reference a third party .NET dll or something that's not default for an ASP.NET Website project (could not find the list of defaults on the net), then a new folder called bin is created & a copy of that dll is stored in it if it is not in GAC.
EDIT: Regarding not able to add a cs file to vb file, I just did that, & I could access System.Xml namespace in the vb file.
Well it looks like it might have had something to do with my trying to add a .cs file to a project where the rest of the files were in vb.net. Hmph, I thought one of the major benefits of .NET was you could easily mix languages. Oh well, I removed that and added these lines into my web.config file:
<add namespace="System.Xml"/>
and
<add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
and now it compiles OK. I can access System.Xml from within VB code, so it looks like I'll have to translate the class I had from C# to VB.net. Hmph.