Unable to find a reference for some old code - c#

I am rebuilding an old project from a long time ago, which i did not create. I've searched around to no avail and cannot find what the reference for "DMB" shown below is. Has anyone come across this before? Or shall I rewrite it?
protected void ErrorText(string error)
{
ErrorLabel.Text = error;
if (playErrorSound && error.Length != 0)
{
DMB.Web.Sound sound = new DMB.Web.Sound();
sound.SoundUrl = "ding2.wav";
ErrorLabel.Parent.Controls.Add(sound);
}
}

Just create a UserControl called Sound with a SoundUrl property. Once you can compile you can see what context it was used in.

Related

GitLab ships a wrong C# code encoding. Ways to fix this

GitLab ships a wrong C# code encoding. Maybe someone might know a reason for this and a way to fix this?
I am working on a project for something like 3 months. All that time I worked from the office, so I did not have to deploy the project locally at my home computer, only at the computer on work. There on work I somehow managed to deploy a project successfully, but here at home while deploying and setting everything up I come across errors in the project.
All due to that piece of code:
public static object ParseReferred(this JObject item, JsonSerializer serializer, RetypeEnum retype)
{
if (item == null)
{
return null;
}
if (retype == RetypeEnum.)
{
return serializer.Deserialize(item.CreateReader(), typeof(TypeRegNumber));
}
return serializer.Deserialize(item.CreateReader(), typeof(TypeTaskNumber));
}
Here is how I see that piece in GitLab:
Here is the GitLab raw view:
Raw code:
public static object ParseReferred(this JObject item, JsonSerializer serializer, RetypeEnum retype)
{
if (item == null)
{
return null;
}
if (retype == RetypeEnum.�)
{
return serializer.Deserialize(item.CreateReader(), typeof(TypeRegNumber));
}
return serializer.Deserialize(item.CreateReader(), typeof(TypeTaskNumber));
}
I suspect that the only one who could have helped me with the issue was my team lead. So, I asked him what I could do about it. He suggested the following: clearing NuGet cache, restoring NuGets, cleaning the solution, and then rebuilding the solution. I followed the steps, but with no success. I feel myself very stupid, I must have missed something.
Is it true that the only way to fix the issue is to communicate with someone who has known the codebase for sometime? Or are there other possible ways to research the issue? I am really stuck, I do not know what I can try to research the issue.
When I hover over the symbol here is what I see:
'RetypeEnum' does not contain a definition for 'ä'
When I open the RetypeEnum definition (by Ctrl+click on the RetypeEnum) here is what I see:
#region Assembly foo, Version=2.0.8.0, Culture=neutral, PublicKeyToken=null
// foo.dll
#endregion
using System.CodeDom.Compiler;
namespace foo
{
[GeneratedCode("xsd", "4.6.1055.0")]
public enum RetypeEnum
{
д = 0,
з = 1
}
}
Try to check out code files line endings.

PortableDeviceManagerClass in C# not able to initialize

I have a c# library which provides some functionallity to upload data onto connected (android) devices. The dll itself gets exported via UnmangedExports to be used by an delphi application.
Here is the function which gets called by the delphi application:
[DllExport]
[return: MarshalAs(UnmanagedType.LPStr)]
public static string getDevices()
{
try
{
var devices = string.Empty;
var collection = new PortableDeviceCollection();
collection.Refresh();
foreach (var device in collection)
{
device.Connect();
if (devices != string.Empty)
{
devices += ";";
}
devices += device.FriendlyName;
device.Disconnect();
}
return devices;
}
catch (Exception e)
{
SomeClass.WriteErrorToLogFile(e);
return "ERROR";
}
}
Here is the class PortableDeviceCollection:
public class PortableDeviceCollection : Collection<PortableDevice>
{
private readonly PortableDeviceApiLib.PortableDeviceManagerClass _deviceManager;
public PortableDeviceCollection()
{
this._deviceManager = new PortableDeviceApiLib.PortableDeviceManagerClass();
}
public bool Refresh()
{
this._deviceManager.RefreshDeviceList();
// Determine how many WPD devices are connected
var deviceIds = new string[1];
uint count = 1;
this._deviceManager.GetDevices(null, ref count);
if (count > 0)
{
// Retrieve the device id for each connected device
deviceIds = new string[count];
this._deviceManager.GetDevices(deviceIds, ref count);
foreach (var deviceId in deviceIds)
{
Add(new PortableDevice(deviceId));
}
return true;
}
else
return false;
}
}
I can create the dll with visual studio and use this inside of the delphi application. When the delphi application calls the getDevices() function, i get an error on the instantiation of the PortableDeviceCollection class:
The file or assembly "Interop.PortableDeviceApiLib, Version = 1.0.0.0,
Culture = neutral, PublicKeyToken = null" or a dependency of it was
not found. The assembly is created by a runtime that is more recent
than the currently loaded runtime and can not be loaded.
ProductXY.PortableDeviceCollection..ctor()
ProductXY.ProductXYMain.getDevices()
The targetframework for the c# project is set to .Net Framework 4. Using any lower version i get an error when i try to compile the project:
The primary reference "Interop.PortableDeviceApiLib" could not be
resolved because it has an indirect dependency on the .NET Framework
assembly "mscorlib, version = 4.0.0.0, Culture = neutral,
PublicKeyToken = b77a5c561934e089", which is a higher version 4.0.0.0
than version 2.0.0.0 in the current target framework.
Please note. I have neither written the c# library nor the delphi application. Both have worked together for years. Now i have to add a functionallity to the c# library. I have not added any code to the project. I just tried to compile it again and use the dll. The only thing i did was updating the RGiesecke.DLLExport.Metadata via NuGet Packetmanager. Without updating i got an error
"Microsoft.Build.Utilities.ToolLocationHelper could not find
ildasm.exe"
I am aware of this Enumerating Windows Portable Devices in C# question. But my error is thrown before the code which is treaded by the question is reached. I still tried the solution to the question, but the action (deassamble, find and replace in the dll) which is described in the answere has already been done (otherwise my code would not have compiled).
The error message doesn't make sense to me. Interop.PortableDeviceApiLib is a COM-Lib which is not available for download in different framework-versions. I think I am missing something here.
Can anyone help me?
I was finally able to solve this problem. To be honest I don't know what finally solved this. For every one who stumbles up on this, here are the things i tried to fix this problem. They are in no specific order (since i tried everything multiple times):
Updating the RGiesecke.DLLExport packet
Changing the plattform in the Konfigurations-Manager to x86
Disassamble, edit and reassable the Interop.PortableDeviceApiLib like in this question (answeres of Christophe Geers and Bruno Klein)
Delete the reference to the Interop.PortableDeviceApiLib
Delete the reference to the Interop.PortableDeviceTypesLib
Readding the reference to the Interop.PortableDeviceApiLib
Readding the reference to the Interop.PortableDeviceTypesLib
Rebuild the project
Setting the Interoptyp embeddet on both to false (I found various statements to NOT do this, but the project was set up like this when i got it and it worked (be carefull)) on both Interop-Libs.
At least this helped me.

Unable to load one or more of the requested types - but not the normal error

Okay, so this is a really bizarre one that has been bugging me. It will be hard to explain so please bear with me!
I am using autofac to register some components by scanning references.
public static void RegisterHandlersKeyedByEnum(this ContainerBuilder builder, Assembly[] assembliesToScan, Type typeToRegister)
{
var handlers = assembliesToScan.SelectMany(a => a.GetTypes()).Where(t => t.GetInterfaces().Contains(typeToRegister));
foreach (var handler in handlers)
{
var handlesAttributes = handler.GetCustomAttributes(typeof(HandlesEnumOf), true).Cast<HandlesEnumOf>();
foreach (var handlesAttribute in handlesAttributes)
{
if (handlesAttribute != null)
{
builder.RegisterType(handler).AsImplementedInterfaces().Keyed(handlesAttribute.Value, typeToRegister);
}
}
}
}
With assemblesToScanBeing:
var assembliesToScan = AppDomain.CurrentDomain.GetAssemblies();
When I run the web app, I get the following error:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
I know what the error is, and have fixed it many times. However if I just refresh the page after ~10-15 seconds, the error no longer appears and the web app is okay to use from then on.
When I looked into this further and inspected LoaderExceptions, the following type was failing to load "Viper.ViewModels.Users.ADUserViewModel". This is where it get's weird. That file does NOT exist, anywhere. Not by searching for files, not even by searching for text. I found out it was a class that was created on a completely separate branch that was never actually merged into master (using GIT).
Now to make it even more weird, if I add in the class ADUserViewModel to Viper.ViewModels/Users folder and even leave the class completely empty. The project runs without any issues/errors whatsoever.
I mean, I could leave the empty class there, it's not doing any harm. But it will really bug me that A) It's unnecessary and B) I don't actually know why this is happening.
Any ideas would be greatly appreciated and put my mind at rest! I'm not sure what code can be posted to help explain this better, but more than happy to provide some if needed.

WPF Cefsharp instance/object reference in class not working

I am spending too much time trying to solve this issue: i am trying to create a Core, because the project is already confusing me and it is not that big. The Core is a Class outside the main Thread. On the main Thread i named the Browser, browser :
<cefSharp:ChromiumWebBrowser x:Name="browser" x:FieldModifier="public" />
In the class i call it like this:
public class Core : MainWindow
{
public void winstenVerlies()
{
var currentdirectory = "https://www.google.nl";
this.browser.Address = currentdirectory;
}
}
I have tried numerous ways, this is the way i like it but they all give me the same message:
"object reference is not set on an instance of an object."
Any help is appreciated.
Problem solved. i researched it for weeks now, from what i can see is the problem is the root, when i use this or the object/function name when calling it, it does not get passed the root of the class, instead of the root of the project. here is how you bypass it.
pass the object trough the class.
public void winstenVerlies(ChromiumWebBrowser b)
{
var currentdirectory = "https://www.google.nl";
b.Address = currentdirectory;
}
then call it like so.
Core Menu = new Core();
Menu.winstenVerlies(browser);
Now i try'd this befor, it gave me error messages the last time, i did not trace the source of the problems.
All i know is it working now, and i am happy.
Have a nice day.

Compilation Error - already defines a member

I've search for a solution for this issue but couldn't find one specific to my scenario.
When i update my test website to try out new changes, I seem to randomly (but frequently) get this compilation error.
CS0111: Type 'Views_warrantyNotification' already defines a member
called 'Page_Load' with the same parameter types
Now on searching for a solution, it all points to having another Page_Load() but i can assure you, there isn't one on the page. I do have an override in the base page, so at the top of the .cs i have ....
public partial class Views_warrantyNotification : CustomBase
{
...
}
then in CustomBase.cs i have...
protected override void OnLoad(EventArgs e)
{
if (!IsPostBack && Directory.Exists(Server.MapPath("~/UploadFiles/") + Session.SessionID)) //if the directory is there on page load then it's come from another form. Delete it!
Directory.Delete(Server.MapPath("~/UploadFiles/") + Session.SessionID, true);
base.OnLoad(e);
}
now this has never been a problem before and I've had this code in place for about 18 months. So I'm struggling to understand why this would suddenly start causing an issue, as such, I'm confused as to why I keep getting this error (randomly).
I've tried recycling the app pool and restarting the website after uploading the updated website files, but this doesn't seem to work.
What I also find strange, is that if I close my browser window and navigate back to the page I'm testing, it will load just fine.
Any idea's would be most appreciated, this is really annoying and it's slowing down my production :(
Thanks

Categories