Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

dynamically loading assemblies


  • Please log in to reply
15 replies to this topic

#1 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 02 August 2012 - 11:14 AM

I'm trying to do the above. it was working ages ago but now all of a sudden my app just hangs!

            byte[] assemblyData = GotSDCard ? File.ReadAllBytes(filename) : ServerHelper.DownloadFile(filename);
            if (assemblyData == null)
                throw new Exception("Assembly was empty");
            try
            {
                Assembly assm = Assembly.Load(assemblyData);
                Debug.Print("loaded Assembly: " + filename);

it hangs on the Assembly.Load call.

In the output window i get

The debugging target runtime is loading the application assemblies and starting execution.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.2\le\SecretLabs.NETMF.Hardware.NetduinoPlus.dll', Symbols loaded.

How can i fix this or see whats going on?

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 August 2012 - 11:29 AM

I'm trying to do the above. it was working ages ago but now all of a sudden my app just hangs!

            byte[] assemblyData = GotSDCard ? File.ReadAllBytes(filename) : ServerHelper.DownloadFile(filename);
            if (assemblyData == null)
                throw new Exception("Assembly was empty");
            try
            {
                Assembly assm = Assembly.Load(assemblyData);
                Debug.Print("loaded Assembly: " + filename);

it hangs on the Assembly.Load call.

In the output window i get

The debugging target runtime is loading the application assemblies and starting execution.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.2\le\SecretLabs.NETMF.Hardware.NetduinoPlus.dll', Symbols loaded.

How can i fix this or see whats going on?


That message in the output window is no error but a success message.
Now you've got an Assembly object 'assm'. All you need to do is execute code from this.

The 'netduinohelpers' repository from Nwazet has an example of how you can do this:
netduinohelpers.codeplex.com -> Helpers/SDResourceLoader.cs
Maybe reading that code could help you out?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 02 August 2012 - 12:12 PM

Thats what I've used but like i said it hangs on the assembly.load and does not return my app just hangs

#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 August 2012 - 12:29 PM

The assembly, which file did you use? It should be a compiled Build/le/*.pe file.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 August 2012 - 12:39 PM

Also, did you compare the file on the card to the original little-endian .PE file, to ensure that no data corruption has occured on the SD card?

#6 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 02 August 2012 - 12:43 PM

its the same size and im using the little endian file. it wont even load it from the sd card if i manually copied the pe file. :(

#7 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 August 2012 - 12:51 PM

its the same size and im using the little endian file. it wont even load it from the sd card if i manually copied the pe file. :(

Could you upload both projects? The app that's loading the assembly, as well as the app that you're trying to load?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 02 August 2012 - 01:22 PM

would love to but it's a commerical project. I'm scrapping this now as I've spent too much time on it. Just wish this device could do OTA updates. Now got to work on a RS422 interface B)

#9 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 August 2012 - 02:42 PM

would love to but it's a commerical project.

I'm scrapping this now as I've spent too much time on it. Just wish this device could do OTA updates.

Now got to work on a RS422 interface B)

Ok :)

I guess you wanted to make an interface for web updates, am I correct?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#10 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 02 August 2012 - 03:58 PM

we could have 100 of these suckers attached to a webserver and it would be nice if the webserver pushed the firmware update.

#11 stotech

stotech

    Advanced Member

  • Members
  • PipPipPip
  • 143 posts
  • LocationAustralia

Posted 12 August 2012 - 03:28 AM

I found this. I don't understand it but it might help. http://fabienroyer.w...ith-a-netduino/

#12 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 13 August 2012 - 07:53 AM

thanks but that was the basis of my code

#13 KevinR

KevinR

    New Member

  • Members
  • Pip
  • 9 posts

Posted 18 December 2012 - 01:02 PM

It might be a bit late, but I found this thread whilst struggling with the same problem, I made some progress which may help others attempting the same thing. I am using firmware 4.2.0.1 on a Plus2, but it should work on a Plus (Plus 1?). Everything worked when the executable loaded was small, however as it grew I ran into problems, here's what I found. Don't run the loader programme in the debugger, it will just seem to hang at Assembly.Load, even if the loaded executable is loaded. Don't use a debug build of either the loader or the loaded .pe file. I'm fairly sure you can attach to and debug the loaded process, but I haven't worked out how yet. Make sure your loaded executable is fully debugged on its own first. Finally, put a Debug.print "Hello" statement right at the start of your loaded programme's Main(), so you can tell if a problem is with the load or with your executable. This is important because that's what mine was doing, it looked like the load was failing, but actually it wasn't, the loaded programme was crashing as soon as it started. Even though it worked fine if it was deployed. I traced the problem to static variables in the class with the Main() which were holding references to classes created in the Main() function. These were correctly set and then suddenly they were magically set to null, between 2 lines of code! I think (speculation alert!) that what happens is that if the .pe is loaded into RAM and started, the garbage collector moves the image in RAM and either moves or destroys these variables. When I removed these variables out of the class containing Main() everything worked fine. Static variables in other parts of the programme are OK. On the Plus 2 I now have a small loader deployed which succcessfully loads and runs a 40k .pe file off the SD card. YMMV, but I hope this helps. Kev.

#14 me62

me62

    New Member

  • Members
  • Pip
  • 7 posts

Posted 21 February 2013 - 02:09 PM

I am using a Netduino Plus 2, with upgraded firmware to v4.2.2 Update 1. I followed all the hints provided in the previous post.  But I found that I had to remove all references to 'static' in my assembly  This is hard to accept that I can not write a program using static.  Is this something to do with .NETMF v4.2?



#15 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 21 February 2013 - 10:17 PM

me62, Can you post a bug report on this at netmf.codeplex.com? The assembly code in NETMF has been pretty stable for several versions--but there was some late work in the 4.2/4.3 cycle to enable additional AppDomain debug scenarios. I'm not sure if that may have affected anything--but I'm guessing that this may just be a limitation of NETMF that can be improved through a framework update. Chris

#16 me62

me62

    New Member

  • Members
  • Pip
  • 7 posts

Posted 27 February 2013 - 03:39 PM

I posted a bug report http://netmf.codeple...m/workitem/1943






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.