Solved

VB and VC# Express 2010 projects and references and platforms oh my!

Posted on 2010-11-14
18
1,198 Views
Last Modified: 2013-11-27
In order to compete, my new VB.NET winforms software application has to include support
for the USBUIRT, an infrared transceiver that allows a PC to learn and transmit
codes for a remote control.   I am programming in the Windows XP environment.


One of his users provided the manufacturer (a term I use loosely, since this guy builds
the USBUIRT more as a hobby) with an inadequate .NET wrapper written in C#.  It works
with standard remotes like TV remotes, but for less common remotes that send their codes
in short bursts (like the remote control for a fan) it did not work.  After some
searching on his web site forum, I found that yet another user had sent him two new files
to replace his source code files in his .net library that would have corrected the
deficiency, had he been able to use them.  (I wish that user had sent him the revised
recompiled .net wrapper library instead, but no such luck)  The manufacturer sent me the
revised files.

He also supplied the source code to the managed wrapper. So I downloaded
MicroSoft Visual C# 2010 Express, loaded the wrapper project, replaced the two files with
the ones the user had supplied, and recompiled.  I got some warnings but when I changed
the warning level, they went away.

Feeling very proud of myself for my ingenuity and persistence, I added the new recompiled
DLL to the reference for my VB.NET project and sure enough, the new functions I needed to
handle short bursts were detected by the intellisense, which is pretty good for a guy who can only program in VB.NET.

BUT  --  when I tried to initialize the reference, I got the following error message:
---------------------------------------------------------
The type initializer for the USBUIRT threw an exception.
Unable to read USBUIRT driver version
---------------------------------------------------------

So its back to his forum, where I found this very useful information:
--------------------------------------------------------------------
The issue is with a 64-bit application trying to load a 32-bit DLL (uuirtdrv.dll)
To correct the problem, change each project in your solution from AnyCPU to x86. To do
this, go to Build --> Configuration Manager. In the platform column, choose (New). Choose
x86 from the New Platform drop down. Uncheck Create New Solution Platforms. Click OK.
Back on the configuration manager window, select the new x86 option for all of your
projects.
Note: You will probably need to load the managed wrapper source code as a project,
reference the project, and force it to compile as x86, instead of just referencing the
already-compiled UsbUirtManagedWrapper.DLL
--------------------------------------------------------------------------------


So I followed the instructions in Microsoft Visual C# 2010 express and recompiled. But
I can only take this so far.  I tried just referencing the recompiled wrapper dll, but the error remains.

I do not think MVB 2010 Express will let me add a project written with VC# 2010 Express.

Unless I am missing something?

So this is where I am stuck.  Neither the user who wrote the original wrapper or the one who sent the revised files are still available, and the manufacturer has been some help, but has not offered to provide an adequate .net wrapper I can actually use in my VB.NET project.

Thanks in advance to anyone willing to tackle this.... (This is one of those times I wish the board would let me award more than 500 points.)  
0
Comment
Question by:codefinger
  • 9
  • 4
  • 3
  • +1
18 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34132638
Did you compile the Debug or Release version? And did you add the reference to the same version?

Also, you should be able to add a C# project to a Solution that contains a VB project (at least you can with the non-Express versions, so i would assume Express will too), so you could try that.
0
 
LVL 14

Expert Comment

by:Matti
ID: 34132659
Hi!

Try this:
http://www.sharpdevelop.net/OpenSource/SD/Download/
You can convert the #C code to VB.NET and add it to your own project, the dubug posibilities are better

Regards!
Matti
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34132666
>> the debug possibilites are better

I'd be very interested to know how, given that they both use the same debugger!
0
 
LVL 14

Expert Comment

by:Matti
ID: 34132695
>> the debug possibilites are better
If it's in the same code not as compiled dll you can set breakpoints etc.
Of cause debug version will display the code line, do a debug compilation of this dll

Regards!
Matti
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34132706
Yes, but there's no need to go through the hassle of converting to a different language to do that.
0
 

Author Comment

by:codefinger
ID: 34133018
Really, I do hope I can accomplish my goal without having to learn an entirely new language.  I have quite a bit of time and code invested in my VB.NET Winforms project.

Also, you should be able to add a C# project to a Solution that contains a VB project (at least you can with the non-Express versions, so i would assume Express will too), so you could try that.

But that is precisely where I am stuck.   MVB 2010 Express says it cannot add project files of type csproj. and suggests I use a different application.

Did you compile the Debug or Release version? And did you add the reference to the same version?

I appreciate that this is a little confusing, so let me try to be more clear.   The USBUIRTManagedWrapper is the C# project.   I add a reference to it from my VB.NET project.
But I did compile a debug wrapper version and that was the reference I added to my VB.NET project, which currently is also still a debug version.   Not sure if that is relevant.



0
 

Author Comment

by:codefinger
ID: 34133044
Ok, this is weird.  I cannot seem to build a Release version with VC# 2010 express, only debug.
I changed the Configuration to Release, but the only files in the BIN directory are all under debug.

What is going on?

0
 

Author Comment

by:codefinger
ID: 34133090
Never mind that last.  I was able to compile an x86 wrapper release version, but I still get the same error from the VB.NET project.
0
 
LVL 12

Expert Comment

by:Hairbrush
ID: 34137770
Hi codefinger

If I understand correctly, you modified the C# project to be x86.  Did you do the same in your VB project?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:codefinger
ID: 34138101
Hairbrush:

I did not.   Will doing so limit the platforms on which it can run, or the drivers it can use?
USBUIRT is not the only transceiver I want the application to support.

0
 
LVL 12

Expert Comment

by:Hairbrush
ID: 34138461
Changing the architecture to x86 will mean that if the application is installed on a 64-bit version of Windows, it will run under WOW64 (Windows on Windows) - see http://en.wikipedia.org/wiki/WOW64 for a description.  I am assuming your application doesn't need to take advantage of 64-bit addressing, in which case this will have no adverse affect.

As for driver support, that should only be an issue in the unlikely event that a transceiver you wanted to use only had 64-bit drivers.
0
 

Author Comment

by:codefinger
ID: 34141990
Took a little work to locate the option in the VB Express version, but when I did I was disappointed to find its been set to build x86 all along.

Still stuck....



0
 
LVL 12

Expert Comment

by:Hairbrush
ID: 34143633
Can you open the C# project and use the "find" feature to find the piece of code that produces the error message "Unable to read USBUIRT driver version"?  Can you paste that code into EE so we can see what it is doing?
0
 

Author Comment

by:codefinger
ID: 34145176
The wrapper project includes a test app which throws the same exception at the line
if (Controller.DriverVersion != 0x0100).   I cannot debug any deeper than that.

See attached...


private static void RunTestApp() 
		{
			Console.WriteLine("UUIRTDRV Example Program...");
			Console.WriteLine("===========================");

			if (Controller.DriverVersion != 0x0100)
			{
				Console.WriteLine("ERROR: Invalid uuirtdrv version!\n");
				return;
			}

			using (Controller mc = new Controller()) 
			{
				mc.Received += new UsbUirt.Controller.ReceivedEventHandler(mc_Received);
				Console.WriteLine("USB-UIRT Info: Protocol: Version={0} Firmware: Version={1} Date={2}",
					mc.ProtocolVersion, mc.FirmwareVersion, mc.FirmwareDate.ToShortDateString());

				while(DoLoop(mc) == true);
				mc.Received -= new UsbUirt.Controller.ReceivedEventHandler(mc_Received);
			}
		}

Open in new window

0
 

Author Comment

by:codefinger
ID: 34145225
There was some more information written to the output console:

UUIRTDRV Example Program...
===========================
UUIRTDRV Example Program...
===========================
An exception was thrown: System.TypeInitializationException: The type initialize
r for 'UsbUirt.Controller' threw an exception. ---> System.ApplicationException:
 Unable to read UsbUirt driver version ---> System.MethodAccessException: Attemp
t by security transparent method 'UsbUirt.Controller..cctor()' to call native co
de through method 'UsbUirt.Controller.UUIRTGetDrvInfo(UInt32 ByRef)' failed.  Me
thods must be security critical or security safe-critical to call native code.
   at UsbUirt.Controller..cctor() in C:\Documents and Settings\Al Knowles\Deskto
p\VERA\usbuirt\api_example_code\UsbUirt_rev1\UsbUirt\UsbUirt Managed Wrapper\Con
troller.cs:line 47
   --- End of inner exception stack trace ---
   at UsbUirt.Controller..cctor() in C:\Documents and Settings\Al Knowles\Deskto
p\VERA\usbuirt\api_example_code\UsbUirt_rev1\UsbUirt\UsbUirt Managed Wrapper\Con
troller.cs:line 54
   --- End of inner exception stack trace ---
   at UsbUirt.Controller.get_DriverVersion()
   at TestApp.Class1.RunTestApp() in C:\Documents and Settings\Al Knowles\Deskto
p\VERA\usbuirt\api_example_code\UsbUirt_rev1\UsbUirt\TestApp\TestApp.cs:line 39
   at TestApp.Class1.Main(String[] args) in C:\Documents and Settings\Al Knowles
\Desktop\VERA\usbuirt\api_example_code\UsbUirt_rev1\UsbUirt\TestApp\TestApp.cs:l
ine 24
Press return to exit.
0
 
LVL 12

Accepted Solution

by:
Hairbrush earned 500 total points
ID: 34145508
Looks like your application will need to run in full trust.  Try following http://support.microsoft.com/kb/815147 for the test app.
0
 

Author Comment

by:codefinger
ID: 34168802
Windows says it is unable to load the assembly:

C:\Documents and Settings\Al Knowles\Desktop\VERA\usbuirt\api_example_code\UsbUirt_rev1\UsbUirt\UsbUirt Managed Wrapper\bin\x86\Release\UsbUirtManagedWrapper.dll


It does not tell me why.
0
 

Author Closing Comment

by:codefinger
ID: 34170438
Not sure if TRUST was actually the issue, it may have been that I was compiling to an incompatible .NET version.
I recompiled the C# code to a lower .NET version  and everything is working now.

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now