Call C# function from Javascript

K

Kannan

Hello,
I know this has been answered before but I cannot seem to get this
working for the life of me... Any help/pointers would be greatly
appreciated.

I am trying to call a set of C# functions from Javascript.... For this
I created a c# class lib. and put all the functions there. The class
library itself references other c# assemblies. The library on its own
works fine...

Here are the steps that I took for this...

1. Create the class library
2. Add functions and declare them as public
3. Add references to System.Runtime.InteropServices
4. Set the "Register for Com Interop" to true in Project Configuration
Properties.
5. Generate a sname file and add it to assemblyinfo.cs
6. Generate unique GUID and declare it before the class declaration.
7. Build the solution from VS.NET
8. Run regasm from the bin/Release folder to register it. (also tried
the codebase option)
9. Add it to GAC using GACUtil


Javascript
===========
1. Attempt to call the Dll using ActiveXObject function

It gives an error "Microsft Jscript Runtime error: Automation server
can't create object" on the above line.

Here are some code samples...

c#
====
using ......
using System.Runtime.InteropServices
---- ------
---- ------

namespace test
{
[GUID("xxxxxxxxxxxxxxxxxxx")]
class test
{
-----
-----
}
}

javascript
=========
var obj = new ActiveXObject(test.test);
 
N

Nicholas Paldino [.NET/C# MVP]

Kannan,

Are you sure that the security settings allow you to create
ActiveXObjects in javascript? If you are running this from a web page, then
the security settings by default will prohibit the object from being
created.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top