vb.net NAudio.dll - Type 'AudioFileReader' is not defined - vb.net

(Visual Studio 2019)
It seems I have run into a snag.
My sample code is this.
Imports NAudio.Wave
Partial Class _Default
Inherits System.Web.UI.Page
Dim filename As String
filename = "G:\VS_Lessons\Media\Read\01. Got to Choose.mp3
Dim reader As New AudioFileReader(filename)
Dim duration As String = reader.TotalTime.ToString("mm\:ss")
reader.Dispose()
Label1.Text = duration
End Sub
End Class
This only happens when I am running the site LIVE and NOT from VS.
Running it through VS, it works as it supposed to.
Running it from a live URL it gives the following error.
Type 'AudioFileReader' is not defined
On this line
Dim reader As New AudioFileReader(filename)
Now, I tried to register the NAudio.dll using. (The NAudio.dll file is in the BIN folder of the website)
gacutil -i NAudio.dll
However, I get the following line
Failure adding assembly to the cache: Attempt to install an assembly without a strong name
I followed the steps in this article here
How to add Strong Name to an existing DLL and install to the GAC
But I get a FAILURE when trying to create the DLL file on STEP 5. (Maybe I am doing it wrong because I am not the owner of the file. Not really sure, this is the first time I have ever done anything like this and was trying everything I could find online)
Any assistance on this would be mighty grateful.
Wayne

The website has to be converted into an Application.
IIS | Web Site |
Right-click on the web site name or sub-folder name
And choose [Convert to Application]
Run the script, and it works.
Now, I have to do this on the live site, but first, I will do the local site, as it runs the same script, and I will get all the bugs out of it, then I can do the LIVE IIS site.

It Could Be Due To Partial Class Instead Of Public Class. Or You Haven't Downloaded Genuine DLL Version Of NAudio.
If Its Problem 1 ( Due To Use Of Partial Class ) Then Change To Public Class
If Its Problem 2 ( Use Of Non-Genuine NAudio DLL ) Then Download NAudio From Here
If Problem Still Persists, Then It Would Be For Windows Form Application.

Related

Custom DLL to avoid the IE web browser control for "unsafe controls" in a tightly controlled and regulated environment

Scenario:
My company has a legacy (read that as 32 bit) windows form application that will be around for quite some time in the future. This application uses an embedded web browser control that is supplied pages that are contained within the database that it maintains. It was built like this so we could extend/modify as needed. I say this so that I can validate that security is not a concern. Only the application and developers with the correct tools have access to the pages or database. The application is only available inside the office.
There are some processes that I need to accomplish using ActiveX objects that are embedded within the pages/application. One of the biggest and most annoying thing that happens is the ActiveX security warning when I got to create instances of things like “scripting.filesystemobject”. Example:
Set oFSO = CreateObject("Scripting.FileSystemObject")
My solution is to create a DLL that is installed locally on each machine that needs access to the extended functions, have the all the functions (whole DLL ??) marked as safe so that the web browser control does not present the security warning. I have been searching using google and came across very few examples, and all of which are in C# which is not my strongest language.
I’ve had to convert from C to Vb.Net visual basic to get what I have now. When I go to register my DLL, I get the following error message:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>regasm
Z:\VBNet2017\APIInternal\APIInternal\bin\Debug\APIinternal.dll /tlb
Microsoft .NET Framework Assembly Registration Utility version 4.8.4084.0
for Microsoft .NET Framework version 4.8.4084.0
Copyright (C) Microsoft Corporation. All rights reserved.
Types registered successfully
RegAsm : error RA0000 : Type 'APIInternal.API.Accupay' has an invalid default COM
interface: 'APIInternal.API.Accupay'
UPDATE: Thank you Hans; the error is gone. I've also made some changes in the source code; I changed the ProgID to something that closely resembles where and what this is for. I'm still having issues in creating the object in VB Script.
This is the output from the current version of the code. This is the code, stripped down for clarity:
Option Strict On
Imports System.Runtime.InteropServices
Imports System.IO
Namespace API
Public Interface IAccupay
<DispId(1)>
Function GetFiles(ByVal Folder As String) As List(Of String)
End Interface
<Guid("8B4B5CEF-8B3A-49A1-9053-E909F82D9E73"),
ProgId("AddIn.Accupay"), ClassInterface(ClassInterfaceType.None),
ComDefaultInterface(GetType(IAccupay)), ComVisible(True)>
Public Class Accupay
Implements IAccupay
Private Function GetFiles(Folder As String) As List(Of String) Implements IAccupay.GetFiles
Return Directory.GetFiles(Folder).ToList
End Function
End Class
I have tried just about every combination of ProgID, Name space, Interface name and class name to get this error to go away without any luck. I do know there are other elements that need to be addressed or added, such as error trapping and, if I’m not mistaken, how to actually implement the ObjectSafetyOption which I still don’t know how to do.
I have been using the Guide at the bottom of this article:
Is it possible to mark an ActiveX object as safe so that IE settings need not be changed?, the second answer, but I haven’t had any success.
Please, can someone point me in the right direction, maybe show me what’s wrong with the code that I have and how to physically implement the ObjectSafteyOption that is needed for the web control. Links, additional reading, code examples or comments on how to get this fixed and working would really be appreciated.
Thank you for reading and any help you send my way, Fred
PS: If you need more information, or have a better solution, please don’t hesitate to reply or comment.
UPDATE:
With the code that I have now, I am able to access the DLL in VB.Net visual basic:
Imports System
Imports APIInternal.API
Module Program
Sub Main(args As String())
Dim API As New Accupay
Dim FileList = API.GetFiles("C:\Windows\")
For Each Item As String In FileList
Console.WriteLine(Item)
Next
End Sub
End Module
However, I still can't seem to get the correct calling for a VB Script/html page:
Set Test = CreateObject("Test.Accupay")
Which returns the VB Script error "ActiveX Component can't create object: Test.Accupay or any other iteration of the parts of the name that I tried. I think part of this is that I don't understand how the creation of the project leads to the creation of the object in a com base environment like VB Script.
Fred
The answer to this problem is two fold: You must target the correct platform (X86) AND use the 32 bit version of regasm. Once I realized this was the issue, I was able to create the DLL and use it's functions in the Web Browser control without the active X warning. One example is I can now open the default browser (in this case, NOT IE/EDGE) from a link within the WB Control and another is to get the contents of a folder for further processing within the WB page.

WebService not running exe

I have referenced a few mentions of how to do this on stackoverflow.
I tried testing from the following reference code :
https://www.dotnetperls.com/process
How to run .exe file by my Webservice?
VERSION: Framework 3.5
VisualStudio2010
When i ran my code below in the browser, I see the bullet point to click on. When I click on it nothing happens. My exe simply locates an xml file and creates a new file from it. I want to use a webservice to run the exe. Is there something I am missing in my code? There are other versions I saw that had more code but I tried them and still had no luck [check my link]
This is my first webservice so I am learning as I go.
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://localhost/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Dim File As String
<WebMethod()> _
Public Sub runExe()
Dim exe = "C:\WindowsApplication1\bin\Debug\WindowsApplication1.exe"
'Dim file = "C:\Test\test.xml"
Dim startInfo As New ProcessStartInfo()
startInfo.FileName = exe
'startInfo.Arguments = file
Process.Start(startInfo)
'REFERENCE: https://www.dotnetperls.com/process
End Sub
I also tried calling .exe from another .exe to run a webservice by using
ThreadPool.QueueUserWorkItem(Sub() Process.Start("C:\WindowsApplication1\bin\Debug\WindowsApplication1.exe"))
but the exe didn't run aka I didn't see the new file created in the folder path the exe sends it to.
also tried:
Dim processInfo = New ProcessStartInfo(exe)
Dim process__1 = Process.Start(ProcessInfo)
process__1.WaitForExit(5000)
Dim exitCode = process__1.ExitCode
process__1.Close()
Return
nothing happened
UPDATE:
Didn't think to use a output test to find my issue. I used the following:
While Not process__1.StandardOutput.EndOfStream
Dim line As String = process__1.StandardOutput.ReadLine()
End While
In response to your comment...
well I'm planning to use my asp.net application to communicate with this service to run exe. so I would think client
That's an incorrect understanding of how web applications work. Your server-side ASP.NET code (the VB parts) are just that, server-side. All of that code executes on the web server. The browser/client/etc. has no knowledge of it.
(Imagine for a moment a world where any website you visit could arbitrarily execute any .NET code they want on your computer. Doesn't sound like fun.)
If you want the client to execute an application, you have to send the application to the client (such as a link to download it) and basically ask them to run it. Your server-side code can't automatically execute applications on the client's computer.

File or assembly name ****.dll or one its dependenies not found

I have added a new service reference to a vb.net dll after excluding the previous one. While debugging, When I am sending a request through a form, the new reference is not able to create a object.exception is at this line:
Dim ObjPricingService As New PricerWebService.MedicalProductService_V2_0
MedicalProductService_V2_0 is the new service reference. The exception is:
File or assembly name ****.dll or one of its dependencies not found.
Source:mscorlib
the name of the *.dll changes every time I debug..so its a random one. the code is built in Visual Studio 2003.
Please provide a solution.
It sounds strange, that the Library changes the name every time you debug. The best thing todo, is to try to set an standard name (if you wrote the library). Also you can try to
Import PricerWebService
and then to use only
Dim ObjPricingService As New MedicalProductService_V2_0
If this will be not fix your problem, try to upgrade your framework + Visual Studio Version (VS2003 what?).
BTW: It would be great if you can send us the error text ;)

Replacing a .NET dll

I have a dll which is installed with the initial installation of my app (via an msi file). The dll contains a user key and this is 'demo' for the initial installation. When a user buys a licence he is provided with another dll which contains his name. The second dll is simply the first, rebuilt with a different name so it is the same GUID and file name.
This works fine on my win7 test machine, I can replace the dll in my apps dir and it runs correctly. I have recently provided a user dll to a new client but the replace method doesn't seem to work. He is quite IT literate so I think he is following the emailed instruction (replace the userdata.dll in your app directory with the attached) it does not seem to change the dll. He is using Win8(pro).
I had thought of sending him an Inno setup to copy the user dll into the app dir, Flags:ignorereversion regserver sharedfile
Can anyone suggest a solution or an explanation?
Later...
I have now sent him an Inno setup for the updated dll and this works. If I used the second dll method (a good idea) I would still need to have the user install it.
Rather than replacing the original .dll, why not provide a second .dll with the customer's specific info? The 2nd .dll will unlock features in the original .dll.
For instance, in your original .dll you might check for Customer.dll:
if(TryLoadAssembly("Customer.dll", out assembly)) {
if(Validate(assembly)){
IsUnlocked = true;
}
}
Further recommendations (and untested samples) - have Customer.dll contain a single object implementing an interface:
class Customer : IToken {
GUID Guid {get;}
// other fields
}
To validate:
bool Validate(Assembly assembly){
Type type = assembly.GetType("Customer");
IToken customerToken = (IToken)Activator.CreateInstance(type);
// check some properties
return customerToken.Guid == application.Guid;
}
You say it doesn't appear to be replacing the DLL. Is it UAC redirecting his filecopy into local storage?
If this is the case then the easiest way to deal with it would be to either
1) supply a batch file that can do the file copy, along with instructions to launch the batch file by right clicking on it anc choosing "run as administrator".
2) supply an executable that can do the file copy. You can either include instructions to run the exe as an administrator like the batch file, or you can include a manifest with the application to instruct windows that the file needs to execute as an administrator.
A last option, which might be worth while for troubleshooting would be to get the user to turn off UAC and try the file copy again. If that works then this user will be happy and you know what the problem is and can find an elegant solution for future customers.
I've just looked on my Win 8 laptop and the option for UAC is in Control Panel - User Accounts - User Accounts - Change user account control settings. This will give a slider which can be slid all the way to the bottom to turn off UAC.
(User Accounts really is listed twice.)

System.IO.Directory.Getfiles Silverlight 4 is not working

I'm using Silverlight 4 OOB & elevated trust.
I need to get all the filenames on specific directory & populate an object List(Of String)
The compiler throws an error "Method not found" on .Getfiles() method.
Dim files() As String = System.IO.Directory.Getfiles(Path) 'this line is failing..
Help!
The GetFiles is marked as "Security Critical" and therefore cannot be used from your code.
You will want to use the EnumerateFiles method instead. GetFiles is sooo .NET 1.0, EnumerateFiles is much slicker, even in the full framework you'd want avoid this older Array returning API if you can.
As far as I know you cannot directly access the whole hard drive using Silverlight OOB.
Quoting from Silverlight site:
When running in a trusted environment, you can access only files in
user folders, specifically the MyDocuments, MyMusic, MyPictures, and
MyVideos folders. Although this makes sense from a security point of
view, it’s limiting. You want to enable the user to drag their data
from any location. As it stands right now, if you try to drop a file
from a location other than stated above, Silverlight will throw a
security error.
Please refer to this link for details on how to work with the hard drive using Silverlight OOB:
http://www.silverlight.net/learn/overview/out-of-browser-applications/advanced-silverlight-out-of-browser-introduction#Exercise3