In a Blazor WebAssembly project with AOT, is there a way to detect at runtime whether a function body is interpreted or runs natively as WASM instructions?
Background. I tried AOT in my Blazor WebAssembly project. I see that dotnet.wasm.xxx file got much bigger and the general performance has improved. However I have doubts about my code that is loaded and called dynamically. I suspect AOT compiler may not be able to discover that code at build time, and therefore it has to be interpreted at run time. Looking for a way to instrument that code to print at run time if it's being interpreted or runs natively.
Related
Our development team has used aspnet_compiler as part of our build process for years to verify our website build. I have noticed that when the process encounters a precompile error, it immediately shuts down. Sometimes, if you fix the issue and restart, it will fail again with another unrelated error that actually existed the first time. I am just wondering if there is a way for it to not "die" and continue the precompile and then list ALL errors that it finds so we don't have to do the iterative process of fixing the errors one at a time.
I have looked at this documentation: https://learn.microsoft.com/en-us/visualstudio/msbuild/aspnetcompiler-task?view=vs-2019 but nothing there seems like it supplies what I am looking for.
do you mean that VS shutdowns, or the external command line build process shuts down? One real problem area is the .net folder called app_code. While you can do a build->compile?
You note that code in that folder does NOT get compiled when you do this. It is only compiled by the build process. Even during debugging, you note that compile errors are not seen (or caught) unless you run (try) the site. As a result? I don't use that folder anymore. The 2nd huge problem is royslen editor code. I have started using that ability's for strings to span multiple lines in - really nice for in-line sql.
However, I find then if you let the web site build, it does NOT support + see and allow such Rosylen formatted code. (so upon run of the site, I get errors). (this might well be due to the web site running IIS 2016 - too old for that new code formatting support (at least in vb.net it is).
So, all I did was create my OWN folder for code and NOT use the .net one ().
Note that you create the folder, but remember for EACH code module, or class you drop into that folder? You have to individual set each to be compiled. (it is the default), but be careful if you import code via add. So you see (and want) to use this option:
So, I of course don't want the source included - and I don't require that since this is a web applicaiton vs a web site.
Thus, I don't get/see/have any runtime compile of my code by the web site compiler process - it all done during the build and even debug process in VS.
And then their is the build for a web site publish. Thus during a deploy build (and publish), I don't get any surprises either.
In other words, the GREAT advantange of a web site applcation is you don't let the web site comile code for you.
You do have to mark the code module as per above.
As a result, this folder behaves like any web form with code behind. The standard debug and build process during development will thus compile all my code - and catach errors.
If you use the built in (and special) folder app_code, then such code only compiles WHEN you run the site, and worse it is the web site that does this compile - NOT VS.
(but of course you publish build process ALSO does this compile!!!).
I need (want) a regular build + compile during the development process to catch and compile all that code (else debugging, and worse compiling means you only can find out issues at web site run time - and that's way too late for my tastes).
So, I don't bother with app_code anymore at all. Now I am lucky, since I am creating (using) a web site application, as opposed to a asp.net web site. (and yes, there is a massive difference).
Asp.net web site = each page and code behind will compile on demand. This choice is perferred for two big reasons:
First, you can update one web page (and code)- deploy that one web page + code. The web server will figure this out - and re-compile that one page on demand. This makes updates and maintains of the site OH SO VERY much easier.
And it also means in most cases that the whole site can be published to a sub-site folder on the hosted web server. And in fact most really cheap low cost web site hosting MUST use this option (web site applications in most cases can't be published to those lower cost .net hosting sites). (thus use web sites, not web site applications).
However, if you lucky, and you have FULL use of IIS and a server dedicated to JUST running your web site? Well, then you are MUCH MUCH better off to go with a aps.net web site application. And this also means you can say setup custom logon providers, and also configure things like re-direction or things like a custom web handier. In effect, this choice means that you as a developer not only have full use of the base starting page, but can directly change/configure the web server to your liking. This includes the base web config.
This choice is often not avaible on lower cost hosting plans. it requires that you have full IIS services, and IIS services is running your whole site, and the base starting page is your site. (you can publish to root on web hosting, but you still using THEIR EXISTING copy of IIS services, and you can't control things like creating a custom authneticaion (logon) provider. And you also can't create re-directs (custom one).
However, in both cases/choices app_code folder behaves like a compile on demand folder. Thus bugs and issues in that folder will thus not be found until you run the web site, or do a full deploy that then does the full site build. and as noted, you can't use Rosylen eiditor souce code features, since the web compiler might be a few verisons old. You be running the SAME .net version, but the older compiler does not support source code formatting with the new Rosylen editor features.
Since a web site application will compile everything (whole site) in your application down to a single .dll (and of course referenced libraries), then then you don't have on-demand occurring by the web site compiler (after you deploy). Of course the publish wizard does have options to combine all those .dll's into one - not a big deal either way.
So, the one exception is app_code. So I just stopped using it, and I see little reason to use that special .net folder anyway.
So, it was never clear if VS is shutting down, or your build process is seeing errors not being caught during the regular development cycle with VS - if this is your issue, then the above approach should solve the problem for you.
How can I faster test changes in Layout using Blazor?
I used to code websites in good old Apache+PHP+MySQL. and now I am starting with some development in Blazor.
But I find it difficult to work on the user interface. When I need to test a small change, for instance moving a entry in a web form from one row to another...
Blazor WASM development process:
Edit the code
Shutdown the browser
Recompile (Pray that it compiles...)
Wait for the webapp+API-App+Identity App to startup
Navigate to the page I am making layout on.
PHP+X Process
Edit the code
Press F5
I wish for a similar experience.
How can I decrease the development code/test UI time when using Blazor?
The simplest way to do interactive development is using dotnet watch run from a command prompt (I add a .cmd script to my projects to run this for the project). This will run the project and watch for changes to files, then re-compile the project.
On .NET 3.x Blazor you'll have to refresh the browser (F5). On .NET 5 projects it does this automatically.
You may also want to read RĂ©mi Bourgarel's Blog article on this, although I am not sure all his points are still valid if you're using .NET 5.
I am new to XUnit. I have bit knowledge to test a WebApplication using XUnit(Created Test class and open XUnit.gui->Open Assembly->TestApplication DLL and RUN). My question is how to test a website using XUnit? My project is created as WebSite and it doesn't have DLL.
There is a similar question relating to NUnit, and the answers there apply here too. The assemblies generated from code in the AppCode folder can't be referenced if they're only generated at run time. This answer shows how they can be generated at build time of your test project. However, as many people point out, you would be better off moving the logic you want to test into a business logic assembly or else converting the project to a Web Application.
Another possibility is to use Selenium to drive the web application through a browser and use the Selenium API in your XUnit tests. This allows for automation of end user tests, which are potentially more useful than just testing the business logic.
If you don't need to be using XUnit and are open to any testing framework, you could also check out Coded UI Tests, which enable a similar type of browser driving testing as Selenium when you use it on websites.
I'm building a Flex/AIR application that connects to a remote server, the URL of which changes depending on the environment (development/production, and possibly others). For now, this URL parameter is hardcoded in my root application MXML file but it means I have to change it everytime I build my app for a different environment.
Is there a way to externalize such a parameter so that when Flash Builder automatically builds my app (in development mode), it uses the development URL (http://localhost...) and when Flash Builder exports a release build, it uses the production URL (http://www.mycompany.com/myapp)?
Flex compiler supports something called Conditional compilation, you an read about it here: link. The problem is that it still doesn't give you an way to check if you're exporting a release build or building for debug. Probably the simplest way to achieve that is to use ANT for compilation of the release build and use the conditional compilation from there.
Is there a way to complie code directly into Native Code instead of MSIL so that we can bypass JIT while executing the code on machine. If its possible. Please let me know the technique also.
Thanks
Compiling MSIL to Native Code Ngen.exe
SUMMARY:
The runtime supplies another mode of
compilation called install-time code
generation. The install-time code
generation mode converts MSIL to
native code just as the regular JIT
compiler does, but it converts larger
units of code at a time, storing the
resulting native code for use when the
assembly is subsequently loaded and
run. When using install-time code
generation, the entire assembly that
is being installed is converted into
native code, taking into account what
is known about other assemblies that
are already installed.
Take look at - How to compile a .NET application to native code?
In the .NET languages I'm familiar with, the source is compiled directly to MSIL. What the JIT does is subsequently compile the IL code to native code.