Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
This code Loads an assembly and creates a new instance of if, how could i do this in an aspx page using javascript?

VB
[Reflection.Assembly]::LoadWithPartialName("MyCustomFrameWork")
$CM = new-object MyCustomFrameWork.Configuration.ConfigurationManager($Web)</pre

<pre lang="C#"><%@ Assembly Name="~/_CONTROLTEMPLATES/MyCustomFrameWork, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f2f41da5e6d39bd0" %>


Doing like this maybe?

But i can not create a new instance of it?

MyCustomFrameWork custom= new MyCustomFrameWork?

In javascript
Posted
Updated 26-May-15 2:01am
v2
Comments
Sergey Alexandrovich Kryukov 26-May-15 9:20am    
Why?
—SA

1 solution

First of all, don't overestimate what happens when you create "assembly". You don't create and assembly as it is understood on .NET, as the main unit of .NET modularity and main functional object of .NET.

You merely obtain a reference to the instance of the class System.Reflection.Assembly:
https://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx[^].

Can you see the difference? This is not the assembly, but the instance of the class representing the assembly as it is understood in reflection technology. Essentially, this is something which allows you to work with assembly types, something which allows you not just to use the assembly metadata to instantiate some classes and fetch any information on the assembly metadata. Depending on how you do it, you can get different in reflection-only content.

You did not bother to explain what you are going to do with the assembly, so I'll just answer your questions.
To load assembly, you need to look at the methods Assembly.Load, Assembly.LoadFile, Assembly.LoadFrom, Assembly.LoadWithPartialName, Assembly.ReflectionOnlyLoad and Assembly.UnsafeLoadFrom:
https://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx[^].

You can create a new instance of the System.Reflection.Assembly object through these methods. There is nothing like "save as"; it would not make any sense. I hope that assigning the Assembly-type variable to another variable will merely create a new reference to the same object, not a new object.

Also, you can generate some assembly on the fly. This is done either via CodeDOM or System.Reflection.Emit. These are the cases when you really create new code on the fly. You did not mention any possibilities like that, so I'll only give you the basic references:
https://msdn.microsoft.com/en-us/library/650ax5cx%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/8ffc3x75%28v=vs.85%29.aspx[^].

How to do it all in ASP.NET? ASP.NET is based on .NET, so the answer is: in the same very ways explained above. Only why? You think about it yourself; you did not bother to explain your idea.

Now, about JavaScript: it has nothing to do with assemblies and .NET and ASP.NET. It is something executed in the browser, that is, in the client part, and ASP.NET works totally on the server part. The only possible role of JavaScript would be just to send some HTTP request to the server side; and the server side can do whatever you program on the server side. To send HTTP request, you need to use AJAX: http://en.wikipedia.org/wiki/Ajax_(programming)[^].

The whole question makes very little to no sense. I'm afraid it's based on some illusions.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900