An unhandled exception of type 'System.TypeInitializationException' occurred in System.dll - vb.net

My visual basic application (targeting Framework 4) was running perfectly until I added code that was originally targeted for Framework 2.0 (specifically altering the column headers of a datagridview). The code executed without problem the first time (when debugging), and thereafter my application won't start. I deleted all the newly added code and debugged, but the errors stayed. I even loaded my backup into Visual Studio, but no change.
I get the following errors and have no idea where to find the source of this problem:
First-chance exception at 0x77cd708f in "app.name".exe: 0xC0000008: An
invalid handle was specified. An unhandled exception of type
'System.TypeInitializationException' occurred in System.dll.
Additional information: The type initializer for 'System.Net.ComNetOS'
threw an exception.
I re-installed Visual Studio and Framework 4. I googled the errors, but nothing pointed me to the location causing the error. I don't believe it's in my code, because I built in try/catch blocks from the very start of the code, even using application events 'startup' and 'unhandledexception', but the app doesn't even start that I may catch the exception stacktrace.
Visual Studio indicates that no symbols are loaded for call stack frame and no source is available. I'm not aware of an error log that might provide details.
Hope someone can help.

This should explain First Chance Exceptions. and how to debug the .dll that causes them

Related

Exception thrown: 'System.Deployment.Application.InvalidDeploymentException' in System.Deployment.dll

.Net 4.7.1/.2 4.8 vb.net
I left my computer on overnight running a task on analyzing some text and when I try to run any project this morning, Application.CommonAppDataPath and Application.LocalUserDataPath throw this exception, but they return the correct values.
I have many projects that use Application.CommonAppDataPath and it's happening in all of them. I created a new project and it happens there, too.
Aside from the clutter in the Immediate window, I'm concerned about what else I may find that throws the exception, so that I spend another hour tracking it down, and what else won't work at all that I haven't encountered yet.
I read every article I could find, there is stuff about ClickOnce (not sure how that is relevant) and corruption in app.config but it shouldn't be happening in new projects.

Getting Error 'HasFile' is not a member of 'FileUpload' VB.NET

I randomly get an error saying HasFile is not a member of FileUpolad.
I'm using a file upload button to upload images to a server. This usually runs; however, every once in a while it errors out. Sometimes the error is caught by Visual Studio during run time, other times it will be a Server Error in Application. Compilation Error when I load the page in debug mode. I've check dependencies and everything seems to be fine. Even the IntelliSense brings up HasFile with I am writing the code.
Usually re-writing the line or restarting Visual Studio resolves the issue, but it keeps coming up randomly.
I happened to figure out what the problem was. Since it was my first time doing this I had a test class in the solution. The test class was named FileUpload. Rookie mistake. I can't believe I didn't catch that earlier!

COMExcepton occurred trying to create a new instance of Microsoft.Office.Interop.Word.Application

I am trying to create a word document using visual basic. I have found that this can be done using the Microsoft.Office.Interop.Word objects.
I have found some tutorials online (https://support.microsoft.com/en-us/kb/316384) about how to create a word document programmatically.
I have created a simple windows form application. When a button is clicked the word document will be created. I made sure to add the reference to Microsoft.Office.Interop.Word in my application.
My problem is that an error keeps getting thrown at this point:
app = New Microsoft.Office.Interop.Word.Application
The error is:
COMException occurred
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Retrieving the COM class factory for component with CLSID (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: ox80080005 (COE_SERVER EXEC FAILURE)).
I have read that the following needs to be done, so I have made sure that word 2013 is installed on my machine and I have set the target CPU to x64 inside the application's properties.
If anyone has any insight to what I am missing or if I am doing something wrong I would appreciate the help.
Update:
I have tested my code on another machine and it works. So the source of this error is not the code.
Update: Pt. 2
I've been doing some more research (http://www.microsoft.com/technet/support/ee/transform.aspx?ProdName=Windows+Operating+System&ProdVer=5.2&EvtID=10010&EvtSrc=DCOM&LCID=1033) and I believe I may be getting closer to the source of the problem. I've gone into the registry and it seems that the local server it is failing to communicate with is pointing to WINWORD.exe which makes sense. What does not make sense is that it is looking for the wrong WINWORD.exe. I am going to try and fix this so it is pointing to the WINWORD.exe for Word 2013 instead of Word 2010.
Solution
What ended up fixing my problem was preforming a quick repair on office. I went to control panel, programs and features, selected office, pressed the change button, and selected quick repair. Do not know what caused things to get messed up, but this did fix my problem.
Where do you run the code? Is it a Windows service or ASP.NET application?
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
You may find existing threads with the same issue described:
System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID
Office Automation in .NET - COMException 80080005
Word Automation with ASP.NET
Finally, if all the mentioned information is not relevant to your case I'd suggest repairing Office. It looks like something is wrong with its windows registry keys.

XAML unhadled exception

I have windows store application. On old systems it worked but now when I run my application on Windows 10 I get strange error
System.ArgumentException: The parameter is incorrect.
Failed to get pointer input transform history.
at Windows.UI.Xaml.Controls.Control.OnPointerMoved(PointerRoutedEventArgs e)
Inner exception is null and I don't know how to resolve this issue. Do you have any tips how do explore source of unhandled exceptions in WPF? Because I have any clue which from my huge amount of controls can cause this error.

Problem with accessing database in windows 7 MS Visual Studio

I developed a small application which accesses a MS access database on my computer using VB.net. I developed the program on windows xp 32 bit. At the moment I am using windows 7 64 bit and the program simply will not run. I get a null reference exception when I try to do anything to the database. I have narrowed this down i THINK to the db provider. I was using Provider=Microsoft.Jet.OLEDB.4.0; and tried using Provider=Microsoft.ACE.OLEDB.12.0;. Neither seems to work. The path to my database is 100% correct. This is the error I am getting:
Null reference exception was unhandled.
Object reference not set to an instance of an object.
Like I say the program runs fine on the windows xp machine. If it helps the access database file extension is mdb.
No DLL exist for 64 bit access to Access database files so you must go to the project properties and on the "Compile" tab go to "Advanced Compile Options" and set "Target CPU" to "x86" I hope this helps.
I was having the exact same problem, except writing to a SQL 2008 DB. VS2008, VB.net code with framework 3.5, Windows 7 64-bit. Code runs fine on XP.
John R's answer provided the right solution: changing the project's advanced compile options to set "Target CPU" to "x86".
This problem can have more symptoms than originally described. I'll generalize them:
Accessing ACCESS isn't the only problem; it happens with SQL (at least MS SQL 2008) too.
Some of the DB calls can and do work. It's as if the calls set you up for failure, but the point of failure happens later, at a random point in your program.
The point of failure I saw was during a subroutine call. (just a normal call to a subroutine I created in VB.) Putting a try-catch block around the call wouldn't catch the error though.
Here's the strangest part: Previous to the errant subroutine call, the code had a HANDLED exception. Ironically, the exception was EXACTLY what was being thrown at the errant call. When I "tweaked" the code to avoid the prior exception, NO exception was thrown at the errant call; the VB program JUST QUIT WITH NO ERROR! It appears that whatever code is having the problem, it is reusing the last handled exception. This would mean that if your code previously had an "index out of bounds" or "divide by 0" error, this is what you'd (probably) see when the code barfs (because of no 64-bit dll.) So this problem can masquerade as a whole bunch of errors!
Doesn't sound like a Provider error because the Jet part is fine. Make sure your Data Source path is correct. If you have it in your Projects folder on VS and are using a full path it may need to change because of how the file system is set up with Users vs Documents and Settings.