I'm trying to recover lost code from a VB.net 2.0 application that I've inherited. I have current working versions, so I've tried using RedGate Reflector and Telerik JustDecompile to recover the code. Both will successfully return code files that are readable and Visual Studio project files, but when I try to run the decompiled program, I get 102 error messages (with both decompilers).
I have working Visual Studio projects from old versions, which run fine, but the structure of the solution and code files is completely different and I'm afraid the program was changed too much since then to trust these old versions.
The only odd assembly that was included is SmartCodeDeveloper 1.0.2986.26049. And I suspect the code was originally written in Visual Studio 2005, as both 2008 and 2012 want to upgrade when the solution is opened.
What else can I do to recover this program? I have the code, but something else is preventing it from running, and I'm at a deadend.
EDIT:
Some of the error messages I'm getting are:
-"End of Statement Expected" or "Statement cannot appear within an event body. End of Event assumed."
-Many are variations on "RemoveHandler" definition missing for object.
-object not declared "It may be inaccessible due to its protection level."
EDIT 2:
Is there any advantage to trying to decompile into C#? Is it possible Reflector may do a better job converting to that? What about different .NET framework versions? I've been doing 2.0, which I believe it was developed on.
I've seen this same problem once before. Described by another member.
Its really simple to correct.
The reason you have these 100+ errors is usually because of something trivial...
Like an unterminated strig for example.
Yet a simple error pushes everything else out of sync so you get more errors displayed than the actual amount of REAL errors, because of the ladder effect that ocurs due to the first error (cause of issue).
The BEST way to deal with it is as follows....
1 - Open your solution
2 - Close all document windows - so no solution documents are displayed
3 - Compile your solution
4 - At this point your errors should be minimised to a much lower amount of errors like maybe 1 to 10 for example.
Try that and let me know how many errors are listed AFTER you have done the above.
Reflector will create code that isn't VB code, ie. var++ . You will have to find them and fix them. It will also create many event definitions that won't work. Look for code Like Public Custom Event definitions. Delete the Custom keyword and all the lines following until End Event. Also you will need to figure out what Import statements you need.
Here is an example from Reflector
Public Custom Event ColumnChanging As DataColumnChangeEventHandler
AddHandler(ByVal value As DataColumnChangeEventHandler)
Bid.Trace("<ds.DataTable.add_ColumnChanging|API> %d#" & ChrW(10), Me.ObjectID)
Me.onColumnChangingDelegate = DirectCast(Delegate.Combine(Me.onColumnChangingDelegate, value), DataColumnChangeEventHandler)
End AddHandler
RemoveHandler(ByVal value As DataColumnChangeEventHandler)
Bid.Trace("<ds.DataTable.remove_ColumnChanging|API> %d#" & ChrW(10), Me.ObjectID)
Me.onColumnChangingDelegate = DirectCast(Delegate.Remove(Me.onColumnChangingDelegate, value), DataColumnChangeEventHandler)
End RemoveHandler
End Event
It would be changed to this :
Public Event ColumnChanging As DataColumnChangeEventHandler
Missing References will cause many errors also.
Related
Using Visual Studio 2008 in order to compile for Windows Mobile 6 devices, I get an issue where changing anything involved in a DataSet results in the error genasm.exe(1): error There was an error finalizing type. GenericArguments[0], 'Mobile_Verification.ScanData+TRANSRow', on 'System.Data.TypedTableBase1[T] violates the constraint of type parameter 'T'. on the next build.
Selecting this error takes me to Microsoft.CompactFramework.Common.Targets, where there is an error on
<Target
Name="BuildAsmmeta"
Condition="'#(None)'!=''">
<BuildAsmmeta <!-- This is where the error is -->
.....(contents)
>
stating The element 'Target' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element 'BuildAsmmeta' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'. List of possible elements expected: 'Task, PropertyGroup, ItemGroup, OnError in namespace http://schemas.microsoft.com/developer/msbuild/2003'. Kind of strange for automatically generated code.
On comparing source controlled code to the new code, I find that Visual Studio has changed all instances of
Inherits Global.System.Data.DataTable
Implements Global.System.Collections.IEnumerable
to
Inherits Global.System.Data.TypedTableBase(Of MyRowName)
Now, in the past, when this has popped up, I've been able to just revert my changes so everything is happy. Now, however, I have some changes of substance to make to the dataset, so I would really like to make this not be an issue anymore.
Searching for solutions, however only seems to give fixes going in the opposite direction: Visual Studio forcing a DataSet when a TypedTableBase is expected. Digging in seems to suggest that the issue might have been introduced to our code when we upgraded from .NET CF 2.0 to 3.5. Apparently TypedTableBase is just the way to do things now, and Visual Studio is enforcing the new paradigm. The fixes suggested here do the exact opposite of what I need.
All well and good, except something is apparently broken in the translation. So now I'm left with three options:
Keep manually fixing it every time I need to change the DataSet
Prevent Visual Studio from automatically changing my DataTables to TypedTableBases.
Figure out what is broken in the new TypedTableBase implementation, and fix that. Specifically, since the error is only being thrown in Common.Targets, and there isn't anything showing in my code, what part of my code is it exactly that the auto-generated code is having a problem with, and how do I get it working?
I would try to find any more details to give, but my boss is telling me it's time to get out of the office. If there is anything else that might shed some light, let me know and I can look for it tomorrow.
Thank you.
After updating from VS 2015 Update 1 RC to VS 2015 Update 1, I keep getting the following error message:
Analyzer
'Microsoft.CodeAnalysis.VisualBasic.CodeFixes.SimplifyTypeNames.VisualBasicSimplifyTypeNamesDiagnosticAnalyzer'
threw an exception of type 'System.ArgumentNullException' with message
'Value cannot be null. Parameter name: source'
on one of my projects. Code Analysis is disabled on that project (as it is on all of my projects in the solution), so I tried to turn it on and off but still the same issue.
It seems that I can still build and run my solution, but things don't really seem to work properly after the upgrade:
everything is running really slow
after making changes and building it doesn't apply the changes
Did anyone else have this issue after the recent update or maybe even before?
Potential work-around found in here: https://github.com/dotnet/roslyn/issues/6682 posted by user dpoeschl.
And this is his original text:
Workaround: Check this checkbox: Tools | Options | Text Editor | Basic
| Code Style | Qualify member access with 'Me'
This workaround has two side-effects (that I can think of so far):
1. You will no longer get a visual indicator of the superfluous Me. or the associated code-fix, or the "Fix all occurrences in" options for
easily achieving compliance.
2. Any code generation features that generate fully qualified member accesses and depend on the Simplifier to remove them if appropriate
(or that explicitly check this option) will now generate non-compliant
code by default.
Enabling this option is particularly non-invasive in both VS2015 &
VS2015 Update 1 because this option is only enforced in one direction.
That is, the checkbox being unchecked means the analyzer runs, does
some deeper analysis (that fails in this case), and offers you a
lightbulb when you have qualified member accesses, while the checkbox
being checked means that we opt out of the deeper analysis very early
and you don't get any lightbulbs telling you to add Me. qualification.
It has worked for me, it might as well fix the problem for others.
This is a defect introduced in Update 1 and it is already tracked at Roslyn GitHub as #6682 since 2015-10-11.
Check there for status updates.
Update: Visual Studio 2015 Update 2 is now out and the problem is fixed there.
Update:
Apparently, the general issue is the code assistant is flagging calls to Shared class types when the class name is used.
For example
Private Shared Property Instance as Class1
Public Shared Function DefInstance1() as Class1
' This causes the warning
Return Class1.Instance
End Function
Public Shared Function DefInstance2() as Class1
' This is okay
Return Instance
End Function
For example, I assigned a value to the Synchronizing Object when inheriting from System.Timers.Timer as:
MyBase.SynchronizingObject = value
Instead of
SynchronizingObject = value
The VS Code Assistant detected this as a type name that can be simplified.
Note also, that a new warning is added each time VS starts.
Update:
It looks like another culprit is in the code generated by Visual Studio in the Application.Designer.vb:
this
Global.Microsoft.VisualBasic.ApplicationServices
is tagged for simplification to
ApplicationServices
It seems that Code Assistant has become a bit over-aggressive without QA noticing the issues at hand.
On March 30th, 2016, Microsoft released a new update for Visual Studio.
After installing Visual Studio Update 2 the issue seems to go away. This is the VS Update 2 and VS Update 2 Release Notes
Checking the Release Notes, this is the only thing they have touched with regards to the Analyzer:
We made Analyzer API improvements, including enabling Analyzer writers to mark their analyzers for concurrent execution, and providing control over whether analyzers run in generated code.
Having a very odd issue with Visual Studio 2013, curious if anyone else is seeing anything similar. I have VS 2013 Ultimate, it seems like once a day, while I'm working with a file, the compiler just suddenly freaks out and doesn't detect my code anymore in my web forms. Take a look at the screenshot below (I just chose a random spot in the middle of the web form), but out of nowhere, VS starts erroring, telling me that variables aren't declared, that method arguments need parenthesis on lines of code that aren't methods, all sorts of whacky stuff.
I assure you, I don't have any broken references, I didn't forget to close an if statement.. nothing like that. All I'm doing it writing some code, and randomly the whole page just starts to error like this. To resolve, all I can do is copy the code contents, delete the page, recreate the page, and paste the contents back into my "new" file... same exact code, only no errors. I wouldn't even worry about doing this if I wasn't doing this at least once a day.
Any help is appreciated, thanks!
Edit: For what it's worth, I found a slightly easier workaround for this issue. If I edit the properties of the class file to "Do not Compile" and then back to "Compile", the IDE is able to read the file just fine...
It looks like this is simply a bug in the Vb.Net Compiler / IDE. I agree it's unlikely to be a bug in your code because you can see that the error squiggles don't line up with places that would represent the errors you are reporting. This is sometimes a sign of an IDE bug
In terms of fixing the problem though you can probably get them to go away by closing and reopening the solution in question. Baring that restarting Visual Studio. I wouldn't resort to deleted / recreating the page.
Long term though you may want to file an issue on connect so the IDE team can try and fix the problem.
http://connect.microsoft.com/VisualStudio
I'm seeing a strange build bug a lot. Sometimes after typing some code we receive the following build error.
Class 'clsX' must implement 'Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs)' for interface System.ComponentModel.INotifyPropertyChanged'.
And
'PropertyChanged' cannot implement 'PropertyChanged' because there is no matching event on interface 'System.ComponentModel.INotifyPropertyChanged'.
Those error should never go together! Usually we can just ignore the exception and build the solution but often enough this bug stops our build. (this happens a lot using Edit and Continue which is annoying)
We're using Vb.net and c# mixed in one big solution.
Removing the PropertyChanged event and retyping the same code! sometimes fixes this.
Question:
Has anyone else seen this problem and has some suggestions how to prevent his?
We're using a code generator that causes this error to surface but just editing some files manually triggers this exception too. This error occur's on multiple machines using various setups.
Someone had the same exact issue discussed here. It sounds like there is an issue with this build picking up an old version of a binary. I would try the following in order:
Verify all assembly references use project references where possible within the Visual Studio solution.
Disable build parallelization in case there is some weird file locking issue with concurrent project builds. Go to Tools -> Options, Projects and Solutions -> Build and Run, then set "maximum number of parrellel project builds" to 1. Not the best solution but it may help narrow down the problem.
Disable the Hosting Process in case it's locking some file causing an assembly to not get rebuilt correctly. For C# project go to Project Properties, Debug tab, and uncheck "Enable the Visual Studio hosting process". For VB.NET project you'll need to Unload Project, Edit the project file, and add <UseVSHostingProcess>false</UseVSHostingProcess> to the PropertyGroup of each configuration. Again, not the best solution but you probably won't notice a difference.
Lastly, try doing a Clean + Build to try and resolve the issue when it occurs (I know this is not a fix but it's easy enough to do), also Rebuild may be slightly different than Clean + Build so try the latter if the former doesn't work.
As I can not comment due to lack of appropriate points.
But I would like to share one of my experience:
In an aspx.cs page I was working, used to compile fine and some time gave mysterious error of a variable not defined or function not defined or sometime variable or the function defined two times. I changed possibly each and every variable and function name but there seemed no effect , but after entering a simple space or a new line at any place in the file used to solve the compile error. At one time I tried to save the file (in a different encoding as i am used to experiments) and found that the file was not saving in the correct encoding (i.e. the ansi encoding because the file had a unicode character ), I removed the unicode character and that compile error didn't bothered me again.
This unicode character problem could be (not a hard and fast rule) there so you could check it.
Nuke & restore using source control (TFS instructions here):
Make sure you have everything checked in
Exit Visual Studio
Rename the project directory to .Bak (effectively deleting it)
Reopen Visual Studio and in source control:
Get Specific Version
check 'Overwrite... not checked out' and 'Overwrite ... even if local version matches'
Re-open project
Another problem: Make sure some source files are not newer than the current date (or your date is set back). Often this happens in apps where you are doing logic that requires certain things to happen differently on certain dates. You change your clock to test it, make a revision to the source with the date advanced, set the date back, and viola, rebuild does not rebuild that file.
You say 'typing it in again' - can you try just saving? After 40 years since MULTIX the .net build still decides what has changed by checking the file timestamp.
good luck!
When you get the error, is it always on the VB calling C# side, or vice-versa, or does it work both ways?
If the answer is either of the first two situations, try building the "callee" project within the solution before building the "caller" project to see if it stops the situation.
Also, just in case it may jog something for you to think about, does this error crop up when you change a VB file or a C# file, or is there no correllation?
Oh, and sorry this looks like an answer instead of a comment, I cannot post comments yet (need 50 rep).
I have a Microsoft Word template with some code and some references, that has been working fine for months but has just started throwing up a spurious "User-defined type not defined" error whenever I open it or try to compile it.
I know it's a spurious error because I haven't made any significant changes to the code. In fact, I've rolled the code back to the last deployed version (which I know works fine) and I still get the error. I've also commented out all the code in the template and I still get the error. I've also removed and re-added all references (same error), and removed all the references and added them back, one by one, until the resultant compile errors are resolved, at which point I'm left with the spurious "User-defined type not defined" error. (I'm going to call this a UDTND error, from now, to avoid driving you all mad.) I think the error started popping up after I rebooted my PC. It only happens with this template, but I don't see how it can be anything to do with this template.
Interestingly, the error is subtly different from a genuine UDTND error in the following ways:
No code is highlighted when the error is displayed.
The dialog is titled "Microsoft Visual Basic", and contains the error message but, unlike a real UDTND error, doesn't contain the text "Compile error:";
It happens when the template is opened, not just when it's compiled (at least, I think that's different from a normal error).
I've tried Googling it but I just get a bazillion results from novice developers asking why they get this error, with responses telling them that they either need to declare the missing type, correct the spelling of the offending variable type, or add a reference to a missing library. I've been banging my head against my screen all afternoon, and that's helped about as much as all the other things I've tried (i.e. not at all). I have a feeling that this is something to do with a messed-up reference, but afaict they're all fine, and I've removed and re-added them, which I would expect to resolve that sort of problem.
Any ideas...?
Your trouble-shooting on References is sound. Once upon a time (and I don't recall the precise error) I was at the same point, and the reference ordering was the key. When you're designating References, you'll notice a "Priority" adjustment feature. Experiment with that and you may solve this.
I have had "User-defined type not defined" problem on several occasions when compiling Microsoft Visual Basic 6 (MSVB6) code that was compiling without a problem earlier. It seems to happen after I have had a long coding session without rebooting the computer. As you can guess, I have been using Microsoft operating systems. I currently am using Windows XP. Rebooting the computer usually fixes the problem as it so often does on Microsoft operating systems.
I have read that fully qualifying declarations also can help, e.g., "Dim oBar as Foo.Bar" instead of "Dim oBar as Bar". I have not tried this approach however.
I had a very similar problem.
My problem appeared (I think) just after I made a Search and Replace that I canceled (Ctrl+Z). There was not highligting of the problem, only the ""User-defined type not defined" error message when I compiled.
I tried:
1) restarting computer
2) changing reference ordering
3) removing functions/procedures, modules one at a time.
Didn't work. My project was written in Excel VBA and here was the solution I found.
THE SOLUTION:
I opened a new Excel file and opened the Visual Basic Editor. I then copied all Forms, Modules, and Class Modules one by one into the new file. I then Copied the Control Objects (3 Commandbuttons) from the old sheet into the new one. Now the new file was identical to the old project - only the ""User-defined type not defined" had gone and problem was solved.
Yea references would be the first step in troubleshooting this problem as already stated, but failing that id start commenting out the code in any event procedures running at start up (my experience is only with Access VBA though)
I had the same problem with Excel 2013.
It started when I did a search and replace on the name of a Custom Class.
I changed the name of the Class after I did the search and replace on all references to it and the spurious error started immediately after that.
I reverted to an earlier version ad confirmed that the problem was not there and then did the same search and replace and re-name and got the exact same behaviour again.
The Custom Class that I changed the name of only had one consumer and it was also a custom class.
I exported, removed and re-loaded the sole consumer class and the problem was fixed.
Check out this link for a Microsoft bug that might be related.
TLDR:
The reference to a package/addin/whatever probably needs to be re-referenced. Check Tools -> References in the Menu.
Also it appears that if you install Microsoft Security Advisory 960715, that certain controls are killed. There are fixes which may or may not work for you. A good article is on this blog:
VSOD Blog