New to unit testing. I need to have an app called SolidWorks start up and load a file. My initialization will not run. I get the error:
Class Initialization method UnitTestProject1.SolidWorksPartTests.MyClassInitialize threw exception. System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly 'SolidWorks.Interop.sldworks, Version=27.1.0.72, Culture=neutral, PublicKeyToken=7c4797c3e4eeac03' or one of its dependencies. The system cannot find the file specified..
I know for certain that the reference in there. I think this has something to do with static references. My code looks like this:
private TestContext testContextInstance;
private static IModelDoc2 model;
private static SolidWorksPart solidWorksPart;
private static ISldWorks app;
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
string testFolderLocation = @"C:\Users\erics\source\repos\XXXXXXXXXXXX\UnitTestProject1\TestFileFolder\";
var progId = "SldWorks.Application";
var progType = System.Type.GetTypeFromProgID(progId);
app = System.Activator.CreateInstance(progType) as ISldWorks;
app.Visible = false;
string testFilePath = testFolderLocation + "FF99999 Circle.SLDPRT";
int errors = 0;
object importData = new object();
app.LoadFile4(testFilePath, "", importData, ref errors);
model = (IModelDoc2)app.ActiveDoc;
solidWorksPart = new SolidWorksPart(model);
}
What is wrong with my class initialization?
EDIT Neither the constructor or the Class initializer runs. The tests I created previously do run though.
I believe I found the problem. I had a setting on my project that I was testing. IT was found on "Properties->Debug->StartAction". I had this set to Start External Program to start Solidworks on debug. I changed this to "Start Project". IT seems to have fixed the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.