I have a project (class library project) with target version .NET Framework 3.5.
I am accessing a string (SplittedPermanentAddressAsString) using get method
if (!Util.isEmpty(cardDetails.SplittedPermanentAddressAsString))
{
permanentAddressStr += cardDetails.SplittedPermanentAddressAsString;
}
and here is the Property
public string SplittedPermanentAddressAsString
{
get
{
if (PermanentAddress != null)
{
return PermanentAddress.SplittedFullAdrsEn;
}
else
{
return "";
}
}
}
When i run the application, i find following error
"Method not found: 'System.String HSDLServerAdminLib.Entity.Card.CardDetails.get_SplittedPermanentAddressAsString()'.
Stack Trace: at HSDLAdminPortal.ServiceImpl.Card.CardViewDetailImpl.viewDetailInfo(Object view, Object res)
at HSDLAdminPortal.Controller.Card.CardDetailsController.worker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
Related
I simply want to see if a string can be converted to any valid type using: System.ComponentModel.TypeDescriptor.GetConverter(type).IsValid(value)) type is System.Type and value is System.String.
I get the following message at Runtime on the line that I call the aforementioned method: System.IO.FileNotFoundException: 'Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.'
Visual Studio also gives me the call stack and the first entry is, External Code.
This exception was originally thrown at this call stack:
[External Code]
MyProgram.Core.Extensions.CanCovertToValue(string) in Extensions.cs
MyProgram.Core.Parser.IdentifyTokens(string[]) in Parser.cs
Program.Main(string[]) in Program.cs
Here's the method it's used in:
public static bool CanCovertToValue(this string value)
{
foreach (Type type in Types)
{
if (System.ComponentModel.TypeDescriptor.GetConverter(type).IsValid(value))
{
if (type == typeof(string))
{
if (value.StartsWith("\"") && value.EndsWith("\""))
{
return true;
}
else
{
continue;
}
}
else if (type == typeof(Uri))
{
if (value.StartsWith("\"") && value.EndsWith("\""))
{
return true;
}
else
{
continue;
}
}
if (type == typeof(char))
{
if (value.StartsWith("'") && value.EndsWith("'"))
{
return true;
}
else
{
continue;
}
}
else
{
return true;
}
}
}
return false;
}
The problem turned out to be that I was trying to iterate through custom structs of a referenced library that references a different version of Newtonsoft.Json. It works perfectly fine with built in C# types.
When calling for this function to create the database, an error occurs System.MissingMethodException: 'Method not found: int SQLite.SQLiteConnection.CreateTable(SQLite.CreateFlags)'
This is where it throws the error during the call for database = new TransmodLocalDB();
App.xaml.cs
public static TransmodLocalDB Database
{
get
{
if (database == null)
{
database = new TransmodLocalDB(0);
}
return database;
}
}
And here is the creation of the tables and the call could not proceed to here.
TransmodLocalDB.cs
public TransmodLocalDB()
{
try
{
database = DependencyService.Get<ISQLite>().GetConnection();
// create the tables
database.CreateTable<Account>(CreateFlags.None);
database.CreateTable<Driver>(CreateFlags.None);
database.CreateTable<Job>(CreateFlags.None);
database.CreateTable<TransportLeg>(CreateFlags.None);
database.CreateTable<Notes>(CreateFlags.None);
database.CreateTable<ImageNote>(CreateFlags.None);
database.CreateTable<Sync>(CreateFlags.None);
database.CreateTable<Enums>(CreateFlags.None);
} catch (Exception ex)
{
var me = ex.Message;
}
}
The exceptions throws before it can create the tables.
Used this library sqlite-net-pcl by Frank A. Krueger latest version 1.6.292
I'm working in a WinForm app in 4 layers:
DAL (Data access)
BOL (Bussiness objects)
BAL (Bussiness access)
INT (Intermediate access).
I'm using the Intermediate layer to run any operation needed by the Presentation layer, trying to make it independent, as we can use it in a WinForm, ASP, and so.
I've created a Class that executes those operations like this:
// Clase: ProjectStatusMID
using System.Collections.Generic;
namespace Trevo.FrameWork
{
public class ProjectStatusMID
{
#region Propiedades
private ProjectStatusBOL _Data = new ProjectStatusBOL();
private ProjectStatusBAL _Operations = new ProjectStatusBAL();
private Acciones _Action = Acciones.Nada;
#endregion Propiedades
public ProjectStatusBOL Data
{
get { return _Data; }
set
{
_Data = value;
}
}
public ProjectStatusBAL Operations
{
get { return _Operations; }
set
{
_Operations = value;
}
}
public Acciones Action
{
get { return _Action; }
set
{
_Action = value;
}
}
public int IDProject
{
get { return _Data.IDProject; }
set
{
_Data.IDProject = value;
}
}
public List<Codigos> ProjectsList
{
get { return LoadProjects(); }
}
public ProjectStatusMID()
{
//Load();
}
public void Load()
{
Operations.Consultar(Data);
}
public List<Codigos> LoadProjects()
{
List<Codigos> oRet = new List<Codigos>();
MyProjectsBAL _Operations = new MyProjectsBAL();
MyProjectsBOL _Data = new MyProjectsBOL();
List<MyProjectsBOL> _MyList = _Operations.Lista(_Data);
foreach (MyProjectsBOL o in _MyList)
{
oRet.Add(new Codigos(o.IDProject, o.Project));
}
return oRet;
}
}
}
// Clase: ProjectStatusMID
At the front-end (in this case is WinForm), we are instancing this class as follows:
ProjectStatusMID OO = new ProjectStatusMID();
So, the issue comes when calling one of the methods:
parProject.DataSource = OO.LoadProjects();
Everything is referenced, the app compiles without any problems, the project that contains the class is part of the solution in a separated project (as any other layer), BUT we have the following error:
System.MissingMethodException occurred
HResult=-2146233069
Message=Método no encontrado: 'System.Collections.Generic.List`1 Trevo.FrameWork.ProjectStatusMID.LoadProjects()'.
Source=WorkLoadPresentation
StackTrace:
en Trevo.FrameWork.PS_ProjectStatus_Datos.CargarListas()
en Trevo.FrameWork.PS_ProjectStatus_Datos.PS_ProjectStatus_Datos_Load(Object sender, EventArgs e) en C:\Users\fbravo\OneDrive\Particular_Sistemas\WorkLoad\WorkLoadPresentation\ProjectStatus\PS_ProjectStatus_Datos.cs:línea 25
InnerException:
I've tried to make the class static, re-creating the entire app, deleting the GAC, and so, but a week loose trying different things.
Any help will be appreciated
Could be several issues. The most common one is that you included the DLL library which is the wrong version (e.g. without the method that's missing). Easiest thing to do is to open the exe in the decompiler (e.g. Reflector) and step through it.
Another issue could be the wrong bitness (but probably not).
You have to make sure you referenced the external project dll in your main Winforms application
I'm having problem using wcf with wp8.1 silverlight. I countinously getting the error The contract 'IPhoneService' contains synchronous operations, which are not supported in Silverlight. Split the operations into "Begin" and "End" parts and set the AsyncPattern property on the OperationContractAttribute to 'true'. Note that you do not have to make the same change on the server. After I changed my syncronous method to async I'm still getting the same error (I updated the service reference.). Out of curiousity I tried to use it on a console app, and it works perfectly.
Previously I did get an another error that might have something to do with it. Adding a service reference generated an app.config file, but the app needed a ServiceReferences.ClientConfig, so I simply renamed it.
For now I changed back the WCF method to syncronous:
public int GetData()
{
return 12;
}
and on my MainViewModel (I'm using MVVMLight toolkit):
public void Load()
{
var client = new ServiceReference1.PhoneServiceClient();
client.GetDataCompleted += client_GetDataCompleted;
client.GetDataAsync();
}
void client_GetDataCompleted(object sender, ServiceReference1.GetDataCompletedEventArgs e)
{
Title = e.Result.ToString();
}
and i implemeneted before the async method like this, getting the same error anyway:
public IAsyncResult BeginGetData(AsyncCallback callback, object asyncState)
{
var msg = 12;
return new CompletedAsyncResult<int>(msg);
}
public int EndGetData(IAsyncResult r)
{
CompletedAsyncResult<int> result = r as CompletedAsyncResult<int>;
return result.Data;
}
class CompletedAsyncResult<T> : IAsyncResult
{
T data;
public CompletedAsyncResult(T data)
{ this.data = data; }
public T Data
{ get { return data; } }
#region IAsyncResult Members
public object AsyncState
{ get { return (object)data; } }
public WaitHandle AsyncWaitHandle
{ get { throw new Exception("The method or operation is not implemented."); } }
public bool CompletedSynchronously
{ get { return true; } }
public bool IsCompleted
{ get { return true; } }
#endregion
}
The problem was VS2013 RC2 version. The reference wasn't generated correctly. An update solved the problem
Sometimes, on my xp machines, I get an exception when calling a method in my auto-generated client proxy. I told the debugger to stop on all clr exceptions.
Now sometimes when I call the following:
public MyStuff.Entities.Package GetPackageById(System.Guid sessionId, int packageId)
{
return base.Channel.GetPackageById(sessionId, packageId);
}
I first get an InvalidOperationException: Collection was modified...
Pressing F10 results in a FileLoadException with the following messge:
Could not load file or assembly 'System.Runtime.Serialization.resources, Version=4.0.0.0, Culture=de-DE, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An operation is not legal in the current state. (Exception from HRESULT: 0x80131509)
I'm sure the service didn't throw an exception because it would show up as a FaultException. Since it's an InvalidOperationException that's being thrown when calling base.Channel.GetPackageById(sessionId, packageId) I assume it's not directly my fault?
I'm slowly running out of ideas what I could try to eliminate or work around this exception.
It never happened when using my developer machine with windows 7 and .NET 4.5 installed on it. On XP this will happen 1 out of 4 times approximately.
GetPackageById on service side looks like this:
public Package GetPackageById(Guid sessionId, int packageId)
{
try
{
return DataProvider.Provider.GetPackagesByKey(packageId,null);
}
catch (Exception ex)
{
throw new FaultException<MySericeFault>(new MySericeFault(ex));
}
}
The Package Class looks like this:
[DataContract(IsReference = true)]
[KnownType(typeof(MyApp.Entities.MachinePackage))]
public partial class Package: INotifyPropertyChanged
{
private DateTime? _outDate;
[DataMember]
public DateTime? OutDate
{
get { return _outDate; }
set
{
if (_outDate != value)
{
_outDate = value;
OnPropertyChanged("OutDate");
}
}
}
private int _productId;
[DataMember]
public int ProductId
{
get { return _productId; }
set
{
if (_productId != value)
{
_productId = value;
OnPropertyChanged("ProductId");
}
}
}
protected virtual void OnPropertyChanged(String propertyName)
{
if (_propertyChanged != null)
{
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
{
add { _propertyChanged += value; }
remove { _propertyChanged -= value; }
}
private event PropertyChangedEventHandler _propertyChanged;
}
This is more of an experiment but too big to put as a comment!
Try creating a new operation contract that performs this code:
Service:
public Package GetPackageByIdTest(Guid sessionId, int packageId)
{
return new Package { ProductId = packageId, OutDate = DateTime.Now };
}
Then create a console application that references your service and write something like this:
Client:
static void Main(string[] args)
{
for (int tester = 0; tester < 2000; tester++)
{
using (var service = new ConsoleApplication1.ServiceReference1.Service1Client())
{
Package result = service.GetPackageByIdTest(Guid.NewGuid(), tester);
Console.WriteLine(result.ProductId);
}
}
Console.ReadKey();
return;
}
Then, try running that on one of the known XP machines that fails and see if you get the same issue. If not it would suggest there is something going a miss in your DataProvider.Provider.GetPackagesByKey(...) method.