PrintForm tool problems

I'm having a strange problem with the PrintForm tool.

I created a Windows form with just a button, that loads a second form, with a docked image, in a PictureBox, and a button, to print the form.

It works fine, BUT... after saving the project, closing VBE, and openning it again, it won't work!

The code is:

PublicClass Form1

PrivateSub Button1_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles Button1.Click

My.Forms.Form2.Show()

EndSub

EndClass

_

PublicClass Form2

PrivateSub Button1_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles Button1.Click

PrintForm1.Print()

EndSub

EndClass

The error is:

System.InvalidOperationException was unhandled
Message="Error creating the form. Refer to Exception.InnerException to details. The error is: This assemblydoes not allow parcialy trusted callers."
Source="ProgramaRDB"
StackTrace:
in WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance)
in WindowsApplication1.My.MyProject.MyForms.get_Form1()
in WindowsApplication1.My.MyApplication.OnCreateMainForm()
in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
in WindowsApplication1.My.MyApplication.Main(String[] Args)
in System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
in System.Threading.ExecutionContext.runTryCode(Object userData)
in System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart()

What are parcially trusted callers?

So, what do I do? I allready re-installed VBE, removed all folders and register references before re-install, and can't get it to work.

Thanks,

Lucas

[4407 byte] By [LucasPasquali] at [2008-1-26]
# 1

Hi Lucas,

I can't reproduce this problem on my machine. Where is the error occurring? Is it when the app first loads?

Steve Hoag

shoagMSFT at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 2

Hi Steve,

This problem happens after saving and closing the project that contains a PintDocument or PrintForm. When I open it and run it again, the problem shows up.

To try solving the problem, I created a simple program on my house's computer, with a picture box and a button, that prints the form to the preview. If I try running it in my work, the form does not show the button that prints the form. If I try runnig it in other computer at work, some problems happens, like a missing .dll, failed .NET Framework, etc.

I don't know what to do, because I promissed a simple program to speed up some process here, and can't even debug it!

I have the last .NET Framework, VB Express, Administrator rights, etc.

If you have some time, could you Build a simple program, that just prints the form out? I would like to test it at home and here, at work, to try figuring out what is the problem. My email, in case you can do it for me, is lucas_pasquali#hotmail.com

Thanks in advance,

Lucas

LucasPasquali at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 3

This is the problem that shows up in anothe PC:

An error occurred creating the form. See Exception.InnerException for details. The error is: Could not load file or assembly 'Microsoft.VisualBasic.PowerPacks.Printing.PrintForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system can't find the specified file.

When I build a program, do I have to install the PowerPack, or any other VB component in the PC I will use it? Doesn't the program created had to be a "closed box", if I make a simple Windows Form?

Thanks,

Lucas

LucasPasquali at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 4

How are you installing the program on the other PC - are you using ClickOnce deployment? The error that you are seeing is due to the PrintForm .dll not being included in the installation, and the program can't run without it. See the following thread for an explanation of how to fix this: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=794377&SiteID=1

- Steve

shoagMSFT at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 5

Hi Lucas,

Have you tried the sample application that was included with the PrintForm download? It should be installed on your Start menu along witth the PrintForm documentation. Give it a try and let me know if you are still having the same problem.

- Steve

shoagMSFT at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 6

Steve, I am simply Building the program, in Build > Build WindowsApplication, copying and pasting the .exe from the C:\Desktop\WindowsApplication1\WindowsApplication1\obj\Debug

Could that be the problem?

LucasPasquali at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 7

Steve, the PrinForm sample works fine on my PC, which has VBE installed. But if a copy the .exe and paste it in another PC, it doesn't run.

I will try it agayn, following the Redistribution post.

Thanks,

Lucas

LucasPasquali at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 8

Yes, that is indeed a problem. If the .NET Framework 2.0 and the PrintForm .dll were already installed on the other computer then copying the .exe MIGHT work, but I wouldn't recommend it. You should use the ClickOnce deployment feature to deploy the application - the following topic should get you started:

http://msdn2.microsoft.com/en-us/library/ms172610.aspx

Note that you will also have to include the PrintForm .dll as described in the Redistribution post that I mentioned earlier.

- Steve

shoagMSFT at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 9

Dear Steve,

I just figured out the problem! I was saving my projects on my work's private net. The first time I opened a saved project, a warning message showed up, because the net was a "non trusted place", and I marcked to never ask me about it again.

Now, that I re-installed VBE, the mesage came up again, and I saved the project directly on the computer, and now it's working! All the problem about opening the project, was the location of the files!

I will try to create the setup files today, but the main problem is solved.

Thank you for the help.

Lucas Pasquali

LucasPasquali at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...