I am trying to use the lame_enc.dll in my C# .NET website and I am stuck.
I am working with: .NET Framework 3.5 / Visual Web Developer 2008 Express Edition / (Anything else you'd need to know?)
The first thing I did was get the code from C# MP3 Compressor on The Code Project. One thing I noted is that this project/post is from January 2004 (so, it's old)
I put the folders "yeti.mmedia" and "yeti.mp3" in my "App_Code" directory and deleted the "Bin" and "obj" directories within each. Then I tried to build the project. When I got errors I ended up excluding from the project the following files:
yeti.mmedia/AssemblyInfo.cs
yeti.mmedia/EditWaveWriter.cs
yeti.mmedia/EditWaveWriter.resx
yeti.mmedia/InFormatEdit.cs
yeti.mmedia/InFormatEdit.resx
yeti.mmedia/NumericTextBox.cs
yeti.mmedia/NumericTextBox.resx
yeti.mmedia/Win32Functions.cs
yeti.mp3/AssemblyInfo.cs
yeti.mp3/EditMp3Writer.cs
yeti.mp3/EditMp3Writer.resx
These seem to me to be the code files related to the Windows UI (which I don't need sonce I'm doing this on the web).
I also put the file "lame_enc.dll" in the Bin directory.
I created a test page based on the example on the page linked above:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using WaveLib;
using Yeti.MMedia;
using Yeti.MMedia.Mp3;
public partial class Documents : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WaveStream InStr = new WaveStream(Server.MapPath(#"Temp/SomeFile.wav"));
try {
Mp3Writer writer = new Mp3Writer(new FileStream(Server.MapPath(#"Temp/SomeFile.mp3"), FileMode.Create), InStr.Format);
try {
byte[] buff = new byte[writer.OptimalBufferSize];
int read = 0;
while ((read = InStr.Read(buff, 0, buff.Length)) > 0) {
writer.Write(buff, 0, read);
}
}
finally {
writer.Close();
}
}
finally {
InStr.Close();
}
}
}
So, then I load this page and the error I get is:
Unable to load DLL 'Lame_enc.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
(I can't add the DLL as a reference in my project because it says "...This is not a COM component.") I have also tried getting the latest and greatest (lame3.98.4) dll and had the same problems. So, I assume there is something different about using this code in a website rather than another type of project. What it is I don't know though.
My guess, having not used LAME, is you have to install in on the box in question. After that, you should be able to use the code project code successfully. If that does not work, it appears Lame_Enc.dll is a native component and you will have to PInvoke methods.
Related
I have a C# program running under Visual Studio 15 .NET Framework 4.5.2. It uses AutoMapper 4.1.1. It's been running fine for years. (I inherited it from someone else.) Just lately, it started erroring out at the line "AutoMappings.AutoMappings.CreateMaps();" Here's the relevant code:
using System;
using System.Windows.Forms;
using IVGOffice.UserInterface;
using System.Net;
using System.Net.Security;
namespace IVGOffice
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// Assign certification callback to allow for self-signed certs on the services
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IVG.Common.Certificate.ValidateRemoteCertificate);
AutoMappings.AutoMappings.CreateMaps(); // <----- Errors out here
It throws a System.TypeInitiializationException with inner error "Configuration system failed to initialize". It never actually enters into the AutoMappings class, so I don't think the problem is related to the class, but here's the beginning of it anyway:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IVG.Common;
using IVG;
namespace IVGOffice.AutoMappings
{
public static class AutoMappings
{
private static bool mapsCreated = false;
private static Utilities2.Services services = new Utilities2.Services();
public static void CreateMaps()
{
// AutoMapper CreateMap should only be called once in an application domain. If we call this twice, check and just leave the second time
if (mapsCreated)
return;
// For every IAutomappedObject
System.Reflection.Assembly assm = System.Reflection.Assembly.GetCallingAssembly();
var interfaceTypes = assm.GetTypes();
var automappedTypes = interfaceTypes.Where(type => typeof(IAutomappedObject).IsAssignableFrom(type)
&& !type.IsAbstract
&& !type.IsInterface);
foreach (var type in automappedTypes)
...
My coworker tried running the same code on his laptop and it worked fine, so there must be something going on with my copy of Visual Studio or my computer settings. I've tried running different versions of the program, rebooting, restoring the program from backup, etc. to no avail.
Anybody have any ideas? Thanks.
I hit this today because I stupidly placed appSettings before the configSections in my app.config file.
The error possibly indicates that your config file contains illegal syntax/layout. I'd start your investigation there.
The problem was in the configuration, but not in app.config. I had added code to save and restore the window status, location, and size. These settings were saved into a new user.config file. The problem was that I had added this code to a new git repo. My boss had to approve the changes before merging them into the master repo. In the meantime, I had gone back to the master to start a new project. The master didn't have the new code, but the new user.config file was still there. For some reason, that seems to have confused the program. When my boss finally merged the new code and I updated my copy of the master, the problem went away. Thanks for your feedback.
I want to create simple toast notification to action center in windows 10 from this example. But I got problem on Step 2:
using Windows.UI.Notifications;
It`s missing. But I have spent a lot of time to find it and got no result. I really have no idea where I can find or at least download it.
What I tried:
After long search I found Windows.UI.dll in C:\Windows\System32 but when I try to add it as reference into project I got this error. Even after I tried to copy it and made this fully accessible nothing changed
I tried to reinstall .Net (I`m using 4.5.2)
Installed Windows 10 SDK
Tried to import with global
Added
<PropertyGroup>
<TargetPlatformVersion>10.0</TargetPlatformVersion>
</PropertyGroup>
Added System.Runtime.dll reference
Example code which probably is useless for you:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.QueryStringDotNET;
using Windows.UI.Notifications;
namespace MessagerClient.Notifications {
class DefaultWindowsNotification {
public static void notificationTest() {
string title = "Andrew sent you a picture";
string content = "Check this out, Happy Canyon in Utah!";
string image = "http://blogs.msdn.com/something.jpg";
string logo = "ms-appdata:///local/Andrew.jpg";
ToastVisual visual = new ToastVisual() {
BindingGeneric = new ToastBindingGeneric() {
Children =
{
new AdaptiveText()
{
Text = title
},
new AdaptiveText()
{
Text = content
},
new AdaptiveImage()
{
Source = image
}
},
AppLogoOverride = new ToastGenericAppLogo() {
Source = logo,
HintCrop = ToastGenericAppLogoCrop.Circle
}
}
};
Console.WriteLine("NOTIFICATION");
//Can`t use because of Windows.UI library
ToastNotificationManager.CreateToastNotifier().Show(visual);
}
}
}
You have to fight Visual Studio pretty hard to use these UWP contracts in a Winforms app. You got off on the wrong foot right away with the wrong TargetPlatformVersion, pretty hard to recover from that. Full steps to take:
Edit the .csproj file with a text editor, Notepad will do. Insert this:
<PropertyGroup>
<TargetPlatformVersion>10.0.10586</TargetPlatformVersion>
</PropertyGroup>
Which assumes you have the 10586 SDK version installed on your machine. Current right now, these versions change quickly. Double-check by looking in the C:\Program Files (x86)\Windows Kits\10\Include with Explorer, you see the installed versions listed in that directory.
Open the Winforms project, use Project > Add Reference > Windows tab > tick the Windows.Data and the Windows.UI contract. Add Reference again and use the Browse tab to select System.Runtime. I picked the one in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\ .NETFramework\v4.6.1\Facades. This reference displays with a warning icon, not sure what it is trying to say but it doesn't appear to have any side-effects.
Test it by dropping a button on the form, double-click to add the Click event handler. The most basic code:
using Windows.UI.Notifications;
...
private void button1_Click(object sender, EventArgs e) {
var xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
var text = xml.GetElementsByTagName("text");
text[0].AppendChild(xml.CreateTextNode("Hello world"));
var toast = new ToastNotification(xml);
ToastNotificationManager.CreateToastNotifier("anythinggoeshere").Show(toast);
}
Embellish by using a different ToastTemplateType to add an image or more lines of text. Do keep in mind that your program can only work on a Win10 machine.
If anyone should happen to stumble on this, see this similar but newer post -
Toast Notifications in Win Forms .NET 4.5
Read Stepan Hakobyan's comment at the bottom.
Essentially, I'm seeing the same thing. This code runs, I can step through it line by line with no exceptions but the toast notification is never shown within a Form app.
I have been baffled on how can this be happening.
So heres the deal, im trying to play a V2M chiptune with a dll called NV2.dll
Its referenced, and I used its functions like normal.
BUT when i try to run the application i get
Unable to load DLL 'V2.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
The referenced DLL i used is called NV2, I have checked it, the assembly goes by NV2, not V2, why is it trying to load a dll with a different name?!
So obviously, there is a reference to V2.dll inside the NV2.dll. Either the documentation is just shitty or you didn't notice that part, but inside the constructor of the NV2 class they try to write that V2.dll, which is saved inside the Resources of the dll as a byte[] V2 to disk, namely to the directory C:\Windows\system32. Code:
public NV2()
{
List<WeakReference> _ENCList = NV2.__ENCList;
Monitor.Enter(_ENCList);
try
{
NV2.__ENCList.Add(new WeakReference(this));
}
finally
{
Monitor.Exit(_ENCList);
}
//Here comes the part that writes the resources
FileStream fileStream = new FileStream(string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.System), "\\V2.dll"), FileMode.OpenOrCreate);
fileStream.Write(Resources.V2, 0, checked((int)Resources.V2.Length));
fileStream.Close();
}
Meaning that either in your application you first have to do a
var engine = new NV2(); //triggers the constructor code
to trigger that, or you go hardcore on that and dump the byte[] from their dll.
I've dumped that file here for you and zipped it: http://www.file-upload.net/download-11263190/V2.zip.html
(You could have done that by saving the project using teleriks decompiler, fixing the errors in the ressources, changing the project to a console project, then coding a Main function like)
using System.IO;
using NV2.My.Resources;
namespace NV2
{
class MainClass
{
static void Main(string[] args)
{
FileStream fileStream = new FileStream("V2.dll", FileMode.OpenOrCreate);
fileStream.Write(Resources.V2, 0, checked((int)Resources.V2.Length));
fileStream.Close();
}
}
}
How to include one c# file into another c# file?
I have two c# file like one is test.cs and another one is main.cs. I want to include test.cs into main.cs.
test.cs file code
// you can use Console.WriteLine for debugging
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Solution
{
public bool solution(long number1, int[,] arr1,int dim_2,int dim_3)
{
//some code here
}
}
main.cs code
using System;
include test.cs;
class Group
{
public static void Main(String[] args)
{
long number1 = 5;
int [,] arr1 = new int[,] {{0, 0},{1, 1},{2, 2},{3, 3},{4, 4}};
int dim_2 = 5;
int dim_3 = 2;
Solution object_class = new Solution();
bool result = object_class.solution ( number1, arr1, dim_2, dim_3 );
Console.WriteLine("Return :");
Console.WriteLine( result );
}
}
what i am doing wrong here?? Please Help me.
Thank you in Advance
I guess your problem is because both files are not added in the same project.
If you are using Visual Studio.
To add test.cs in the Group class project.
Go to Solution Explorer -> Add Existing item -> Browse your file i.e.
test.cs -> OK
If you are using DOS mode.
Make sure that both files must be in same folder.
And in either case. first delete include test.cs; from Main file. then Compile & RUN
We create object of classes declared in other source code files with the way you have already followed:
Solution object_class = new Solution();
Provided that the Solution class is declared in a source code file in the same project (console application as I can infer from your post), you don't have to mark the Solution class as a public. Otherwise, you should mark it as a public. Actually, you have to do so in case of this class is going to be used outside of your current project.
Your problem, I think is about namespaces. You might have declared this class inside a folder. Anyways, the way to solve this is to right click on the name of the Solution and then click resolve references.
ASP.NET C# Classes
this solution was helpfull for class files outside the App_Code
you need add follow line in every page(aspx) or usercontrol(asc)
<%# Assembly Src="~/App_Ctrl/PraxisPdfs/class_pdf.cs" %>
So i have simple application, just a few lines:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectInput;
namespace asdasd
{
public partial class Form1 : Form
{
public Device joystick;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (
DeviceInstance di in
Manager.GetDevices(
DeviceClass.GameControl,
EnumDevicesFlags.AttachedOnly))
{
joystick = new Device(di.InstanceGuid);
break;
}
if (joystick == null)
{
throw new Exception("No joystick found.");
}
}
}
}
and i try to get the active joystick on my computer, but i get error:
i have the assembly Microsoft.DirectX.DirectInput and i have directX SDK 2010 installed.
Can someone tell me where is the problem?
Try adding this to the config file:
http://devonenote.com/2010/08/mixed-mode-assembly-error-after-upgrading-to-dotnet-4-0/
(if configuration already exists, just merge these in)
And, maybe it's not the right place, but just take a look at XNA... Things are usually much easier with that.
I couldn't paste the XML directly here, it doesn't show up.
The DirectX assemblies are built against .NET v1.1 Microsoft stopped actively developing them before .NET v2.0 was released.
They cannot be used in projects targeting other than .NET v1.1. XNA is the "blessed" path forward for managed access to Direct X features. I don't know all if it's features, but SlimDX appears to give a more Direct X feeling API for C# than XNA, though I have not used it, I've heard a lot about it.
You might find better responses for chosing an upgrade path over at gamedev.stackexchange.com though.