VSIX - Cannot load file or assembly of a referenced dll - visual-studio-2012

My question is very similar to this one, only that the answer and work-around are not working for me. Also I am in Visual Studio 2012.
I have a VSPackage which is referencing another project, which is dependent on other dlls. Everytime time I run my package in debug I get an exception that the other dlls cannot be found. They are in the output directory, and they are signed.
I tried referencing them directly by the VSPackage project to no avail.
Thoughts?

This problem exists because Visual Studio is not looking for assemblies in a folder of your extension if your extension has no explicit dependence on these assemblies. For example, dependences set in a configuration file (IoC config) or in xaml code. I know three solutions to this problem:
You can deploy these assemblies in the GAC and Visual Studio will load them. This method is good if you use a third-party library that built for use in the GAC (for example, MS Enterprise Library). But VSIX Deployment Package does not allow installing assemblies in the GAC, you can use the MSI installer.
For VSPackages for Visual Studio 2010/2012 you can use ProvideBindingPath attribute. The path where your extension located will be added to the paths that Visual Studio uses to find dependent assemblies. If your extension doesn't include a VSPackage, you can add this attribute to any public class (see here).
[ProvideBindingPath]
public class MyVsPackage : Package
{ /* ... */ }
You can manually resolve assembly names. To do this, you need to subscribe to the AssemblyResolve event and you need to return required assemblies from a handler. This is the most flexible way, if you cannot use the previous methods, this is especially for you.
In my IntelliDebugger project, I wrote a class ManualAssemblyResolver for it:
using System;
using System.Reflection;
namespace IntelliEgg.Debugger.Utility
{
public class ManualAssemblyResolver : IDisposable
{
public ManualAssemblyResolver(Assembly assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
_assemblies = new[] {assembly};
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
}
public ManualAssemblyResolver(params Assembly[] assemblies)
{
if (assemblies == null)
throw new ArgumentNullException("assemblies");
if (assemblies.Length == 0)
throw new ArgumentException("Assemblies should be not empty.", "assemblies");
_assemblies = assemblies;
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
}
public void Dispose()
{
AppDomain.CurrentDomain.AssemblyResolve -= OnAssemblyResolve;
}
private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
foreach (Assembly assembly in _assemblies)
{
if (args.Name == assembly.FullName)
{
return assembly;
}
}
return null;
}
private readonly Assembly[] _assemblies;
}
}
This class must be created before the first call to the problem assembly (e.g., in Package::Initialize() method)

Related

Missing reference to netstandard for Cppsharp program

I'm trying to start my first project with Cppsharp using Visual Studio 2015, following the getting started guide.
The steps I followed were to:
Create new C# console project
Install Cppsharp using Nuget
Add references to Dlls into the project
Create C# source file based on the example in this old post
Whilst the example in the post is old, it still seems to be consistent with the getting started guide. The full program is listed below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CppSharp;
namespace CppSharpTest
{
class Program
{
class DllDemoGenerator : ILibrary
{
static void Main(string[] args)
{
ConsoleDriver.Run(new DllDemoGenerator());
}
void Setup(Driver driver)
{
var options = driver.Options;
options.GeneratorKind = LanguageGeneratorKind.CSharp;
options.LibraryName = "DllDemo";
options.Headers.Add("DllDemo.h");
options.Libraries.Add("DllDemo.lib");
}
public void SetupPasses(Driver driver) { }
public void Preprocess(Driver driver, CppSharp.AST.Library lib) { }
public void Postprocess(CppSharp.AST.Library lib) { }
}
}
}
However, I am already facing errors See image:
CS0012 C# The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=...'
I was not able to find a way to add this reference. One solution I found proposed to target a higher .NET version (4.7.2) and I tried this, but the error still remains.
Can anyone help to overcome this problem?
Posted the same question on the Github page and was recommended to upgrade from VS2015
Installing VS2019 removed this error

How to access Custom field,which is defined in Construction feature package- Acumatica

By reading my question, you might think its very easy, but i request everyone to try to access a custom field defined in the construction feature package.
I want to access "Type" field in Project screen's Task Tab in details
UsrType is a custom field defined in Construction features package. In that package, file has been converted into dll. I tried to access that field like we usually do in customization.
but i got error
Type or Namespace "PMTaskExt" could not be found
I even tried this
I got error
UsrType Doesn't exist in PMTask
There is also same problem with UsrSubcontractNbr field in APTran. Not Only these fields, there are many such field to be accessed.
How can we access such fields?
From looking at PX.Objects.CN.dll it would be in the PX.Objects.CN.ProjectAccounting.PM.CacheExtensions namespace as PmTaskExt
Used the latest 19R2 Construction project "ConstructionFeatures_19_205_4_1_157"
Decompiled the customization dll (used DotPeek) I searched for PMTask:
Copied text:
using PX.Data;
using PX.Data.BQL;
using PX.Objects.CN.ProjectAccounting.PM.Descriptor;
using PX.Objects.CS;
using PX.Objects.PM;
namespace PX.Objects.CN.ProjectAccounting.PM.CacheExtensions
{
public sealed class PmTaskExt : PXCacheExtension<PMTask>
{
[PXDBString(30)]
[PXDefault]
[PXUIField(DisplayName = "Type", Required = true)]
[ProjectTaskType.List]
public string UsrType { get; set; }
public static bool IsActive()
{
return PXAccess.FeatureInstalled<FeaturesSet.construction>();
}
public abstract class usrType : BqlType<IBqlString, string>.Field<PmTaskExt.usrType>
{
}
}
}
Something like this should work:
var cnExt = PXCache<PX.Objects.PM.PMTask>.GetExtension<PX.Objects.CN.ProjectAccounting.PM.CacheExtensions.PmTaskExt>((PX.Objects.PM.PMTask)e.Row);
Do note the .Net version of PX.Objects.CN.dll is using 4.8 in case that causes any issues with version compatibility in visual studio if your solution is compiled on the same version of Acumatica for 19R2 which is 4.7.1

accessing Android native method from different project

I am working on an Android application that will call a .so file created by a different Android NDK application.
I have created the following folder structure in my project and copied over the .so files as seen below:
|--app:
|--|--src:
|--|--|--main
|--|--|--|--jniLibs
|--|--|--|--|--armeabi
|--|--|--|--|--|--libmylib.so
|--|--|--|--|--x86
|--|--|--|--|--|--libmylib.so
I call this library through my application via the following code:
static {
System.loadLibrary("mylib");
}
I then call the method from this shared object via the following code:
String str = stringFromJNI();
This does not work as the program looks for mangled function name as follows:
com.example.androidlibcall.MainActivity.stringFromJNI() where my .so function will be using a different package name and hence a different function name is generated.
I am not really sure what I need to do to call the functions from the external library, I assume I can create my own library and utilize dlopen() to load the external library and make calls to it, but was wondering if there are the other methods to achieve this or not.
My ultimate goal is to be able to create applications that can call pre-existing libraries that are on the mobile device, but since I am new to NDK/Android I am not sure what is the best method for this and have not found good examples to work with.
A lot of the pre-existing similar questions seem to be dealing with older versions of Android Studio that don't seem applicable anymore.
I am using the latest version of Android Studio (3.1.2) with Gradle 4.4 on Windows 7 machine.
Please advise.
Thanks!
Generally speaking, it's not a good idea to have native methods in application's MainActivity, but this should not worry us now that we are forging a workaround.
Assume that your new project has com.example.other.MainActivity.java, and you want to call the native method com.example.androidlibcall.MainActivity.stringFromJNI() from com.example.other.MainActivity.onCreate(). To do this, create a new Java class in your other app:
package com.example.androidlibcall;
public class MainActivity {
public static native String stringFromJNI();
}
and in your existing MainActivity class,
package com.example.other;
import static com.example.androidlibcall.MainActivity.stringFromJNI;
class MainActivity {
static {
System.loadLibrary("mylib");
}
}
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
…
String qq = stringFromJNI();
…
}
}
You see that com/example/androidlibcall/MainActivity.java contains no logic, no data, no code. It is only a wrapper that lets us easily use libmylib.so without rebuilding it.

iOS Project Fails to Compile

When compiling iOS project developed with MvvmCross version 3.5.0, I get the following error:
Failed to resolve "Foundation.NSDate Foundation.NSDate::op_Explicit(System.DateTime)" reference from "Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065"
You are likely using an outdated version of MvvmCross (or another 3rd party) that used an old, preview version of the unified API.
The error tells you an assembly (binary) is looking for a member that it cannot find, because it was removed: see section "Converting DateTime to NSDate".
Updating your dependencies (any assembly binaries) will solve this correctly, without potentially introducing other issue(s).
The bug is in the method:
public void Include(UIDatePicker date) in LinkerPleaseInclude class.
Trying to pass DateTime as NSDate.
Just comment out or remove following code :
public void Include(UIDatePicker date)
{
date.Date = date.Date.AddSeconds(1);
date.ValueChanged += (sender, args) => { date.Date=NSDate.DistantFuture; };
}
Also can be resolved by updating binary libraries to unified api.
You can get detailed information on
http://developer.xamarin.com/guides/cross-platform/macios/unified/

Using $safeitemname$ in VS2012 Item Template causes value to appear as inheriting class also

Inside my template file I use the safeitemname template variable to define my class name. The Item Template is intended to create a class that subclasses MXApplication. The result after exporting the template and utilizing it to create a new class is essentially the class inherits from itself. If I try adding a namespace to the class, I just get the namespace prefixed before the value substituted for safeitemname.
Here is the Template class (trimmed for explanation purposes):
namespace $rootnamespace$
{
public class $safeitemname$ : MonoCross.Navigation.MXApplication
{
public override void OnAppLoad()
{
//Do the work
}
}
}
The result when I use the template to create MyApp is:
namespace MyNameSpace
{
public class MyApp : MonoCross.Navigation.MyApp
{
public override void OnAppLoad()
{
//Do the work
}
}
}
I've tried to export this template using VS2012 (and VS2013).
Any advice would be much appreciated. I've been trying to update my Item Templates in Visual Studio 2012 (they worked in 2010) but I keep running into this issue. I've tried it on several of my existing templates; and even tried recreating the .csproj and adding my existing templates to the .csprog file created using Visual Studio 2012. All of my attempts result in the same class inheritance issue.
This is the MSDN Doc I've been using for reference:
http://msdn.microsoft.com/en-us/library/vstudio/tsyyf0yh.aspx
The issue was apparent when looking at the .zip file created by the Export Template command. The .cs file contained within the template .zip read:
namespace $rootnamespace$
{
class $safeitemname$ : MonoCross.Navigation.$safeitemname$
{
public override void OnAppLoad()
{
//Do the work
}
}
}
The fix to get my template working was to edit the .cs file manually and replace the last $safeitemname$ with MXApplication and then stick the .cs file back in the .zip file where it came from.

Resources