Invalid object name 'dbo.EdmMetadata' - c#

I keep getting this error on initial load of my application. I have searched high and low and the only thing I found to do was the code below in my context.
Database.SetInitializer<Context>(null);
I have this set in the OnModelCreating method but it is still throwing the error below:
System.Data.SqlClient.SqlException: Invalid object name
'dbo.EdmMetadata'.
System.Data.Entity.Core.EntityCommandExecutionException: An error
occurred while executing the command definition. See the inner
exception for details.

You should add this code in constructor of your Context class.

Related

changedirector.update(TrackedObject item) throws null reference exception

When looking on the internet for this error i get one hit that is close to the error i am getting. It can be found here: https://social.msdn.microsoft.com/Forums/en-US/8ab51524-e8d5-4eb3-acba-4ff024142e57/nullreferenceexception-in-getupdatecommand-during-submitchanges-call?forum=linqtosql
The solution provided by this person was to rewrite the code, however this is not really an option in this case.
So what happens is that I open a new datacontext connection to our database using linq to sql. Then with or without updating a record a submitchanges is called and the following error is thrown:
Exception: Object reference not set to an instance of an object.
(no InnerException)
StackTrace: at System.Data.Linq.ChangeDirector.StandardChangeDirector.Update(TrackedObject item)
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at Brainsch.DLinq.BrainschDataContext.SubmitChanges(ConflictMode failureMode)
This exception keeps recurring until the application is restarted. After the application is restarted it does not occur any more.
I found the code part where this error happens(https://referencesource.microsoft.com/#System.Data.Linq/ChangeDirector.cs,f4d313ee41bcda98) and looking at that code gives me many options where the null reference exception occurs.
Can anyone share some light on why this error occurs and how to circumvent it.

Can I get the method that was first called in an error routine?

I am trying to get the method that called a method in an assembly that caused an error.
I have an error routine that logs errors. I would like to get the calling assembly and method along with the assembly and method where the error occurred. I got 3 out of 4, I just cant figure out how to get the calling method.
Say I have a form and a button is clicked that calls a method in another asssembly that errors. I want the assembly and method where the error occurs along with the form and click event. The click event is what I can't find.
VB
Dim Trace As System.Diagnostics.StackTrace
Trace = New System.Diagnostics.StackTrace(ex, True)
'Returns the assembly where the error occurred
Trace.GetFrame(Trace.FrameCount - 1).GetMethod.ReflectedType.FullName
'Returns the calling assembly
Assembly.GetCallingAssembly.FullName.Split(","c)(0)'Would be nice to get the class too but I can live without it.
'Method where the error occurs
ex.TargetSite.Name
'Initial calling method
???
C#
System.Diagnostics.StackTrace Trace;
Trace = New System.Diagnostics.StackTrace(ex, True);
//Returns the assembly where the error occurred
Trace.GetFrame(Trace.FrameCount - 1).GetMethod().ReflectedType.FullName;
//Returns the calling assembly
Assembly.GetCallingAssembly().FullName.Split(',')[0];//Would be nice to get the class too but I can live without it.
//Method where the error occurs
ex.TargetSite.Name;
//Initial calling method
???
I can see the source in the stack trace (Main.btnCancel_CLick but can not get it. My stacktrace frame count is 1 and I have one method in there, the one with the try catch block. Unless there's some other way to get to it that I can't figure out. Anyone know?

Operation completed successfully when using resource

My winforms project is throwing this error:
"Exception thrown: 'System.ComponentModel.Win32Exception' in
System.Drawing.dll
Additional information: The operation completed successfully"
at this line:
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
The line is inside the auto generated code for the designer, so I'm not sure why it's throwing an error. I didn't edit it in any way, please help.
EDIT:
this is not a duplicate, the other question is quite vague on the actual code.
EDIT #2:
The error is now popping up at the designer of resources.resx, with the message
Parameter not valid
it now appears at this auto-generated code:
internal static System.Drawing.Bitmap WoodTex
{
get {
object obj = ResourceManager.GetObject("WoodTex", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
resourceCulture appears to be null, is this a different error entirely?

Calling original method in shim class

I want to test a repository against some erronous network behavior. I faked the class using MS Fakes and it looks like this:
ShimInputRepository
.AllInstances
.UpdateEngagementStringNullableOfInt64NullableOfInt32String = (xInst, xEngId, xTrimUri, xTargetVers, xComments) =>
{
if (xEngId != initializer.SeededEngagementsWithoutEmp[3].EngagementId)
{
return xInst.UpdateEngagement(xEngId, xTrimUri, xTargetVers, xComments); //Unfortunately, calls recursively same method (not the original one)
}
else
{
throw new Exception
(
"An error occurred while executing the command definition. See the inner exception for details.",
new Exception
(
"A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)"
)
);
}
};
I don't know how to call the original method from withing that code (currently it recursively calls same method).
How to call the original method?
UPDATE: What I really want to achieve is to throw an exception on a specific call to this method (the "if() ..." statement) and forward the call to original instance otherwise.
The Fakes framework provides support for just such an occasion. You can use:
ShimInputRepository
.AllInstances
.UpdateEngagementStringNullableOfInt64NullableOfInt32String = (xInst, xEngId, xTrimUri, xTargetVers, xComments) =>
{
if (xEngId != initializer.SeededEngagementsWithoutEmp[3].EngagementId)
{
return ShimsContext.ExecuteWithoutShims(() => xInst.UpdateEngagement(xEngId, xTrimUri, xTargetVers, xComments));
}
else
{
throw new Exception
(
"An error occurred while executing the command definition. See the inner exception for details.",
new Exception
(
"A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)"
)
);
}
};
The ShimsContext.ExecuteWithoutShims method will execute the Func< T > outside of the current shim context (e.g. without the shim redirection which was causing you your infinite loop).
The cause of your infinite loop is that creating a ShimContext modifies your assembly at runtime. As long as the context is active, all invocations of the shimmed method are redirected to the static method on the shim class. You need to explicitly go outside the shim context for the portion of code you want to execute as normal.

'System.Reflection.TargetInvocationException' when calling Activator.CreateInstance()

I am receiving this error:
A first chance exception of type 'System.Reflection.TargetInvocationException'
occurred in mscorlib.dll
and also:
Exception has been thrown by the target of an invocation.
when running this method, and the error is occurring on the CreateInstance(Type.GetType(instantiationString), parameters) call:
public static Report instantiateReport(ReportInfo reportInfo)
{
string instantiationString;
Report reportToReturn;
ReportInfo[] parameters = new ReportInfo[1];
parameters[0] = reportInfo;
instantiationString = reportInfo.Report.InstantiationPath;
reportToReturn = (Report)Activator.CreateInstance(Type.GetType(instantiationString), parameters);
return reportToReturn;
}
ReportInfo is just a custom class that contains variables that help me build the report that I am trying to instantiate and when I investigate it, everything is completely fine. The instantiationString just helps me understand which report is trying to be created at the call and that way I can use the Type.GetType() method. I really have no idea what kind of error this is or what could be going wrong. I researched it a bit but didn't receive any helpful answer so any help is appreciated.
EDIT After looking at the inner exception I am getting Object reference not set to an instance of an object. message. This is strange because neither the ReportInfo or the GetType() methods have a null reference. Say one of the variables within ReportInfo was null, could that cause an issue? It shouldn't right?
FIXED After delving into the stack trace of the inner exception I found that there was some conflicting code causing issues elsewhere. Problem solved.

Categories

Resources